美文网首页
find命令/文件名后缀

find命令/文件名后缀

作者: hch004 | 来源:发表于2017-12-23 09:08 被阅读0次

    Linux下find命令在目录结构中搜索文件,并执行指定的操作。Linux下find命令提供了相当多的查找条件,功能很强大。由于find具有强大的功能,所以它的选项也很多,其中大部分选项都值得我们花时间来了解一下。即使系统中含有网络文件系统( NFS),find命令在该文件系统中同样有效,只你具有相应的权限。 在运行一个非常消耗资源的find命令时,很多人都倾向于把它放在后台执行,因为遍历一个大的文件系统可能会花费很长的时间(这里是指30G字节以上的文件系统)。

    1.命令格式:

    语法 :find[路径][参数]

    ‘-atime +n/-n’ : 访问或执行时间大于/小于n天的文件

    ‘-ctime +n/-n’ : 写入、更改inode属性(例如更改所有者、权限或者链接)时间大于/小于n天的文件

    ‘-mtime +n/-n’ : 写入时间大于/小于n天的文件

    -type  查找某一类型的文件,诸如:

    b - 块设备文件。

    d - 目录。

    c - 字符设备文件。

    p - 管道文件。

    l - 符号链接文件。

    f - 普通文件。

    [root@localhost ~]# yum install -y mlocate    安装find

    [root@localhost ~]# find / -type f -mtime -1  查找一天以内的文件

    [root@localhost ~]# find /etc/ -type f -mtime -1  查找etc文件夹一天以内的文件

    /etc/resolv.conf

    /etc/group

    /etc/gshadow

    /etc/tuned/active_profile

    文件的 Access time也就是 ‘atime’ 是在读取文件或者执行文件时更改的。文件的 Modified time也就是 ‘mtime’ 是在写入文件时随文件内容的更改而更改的。文件的 Change time也就是 ‘ctime’ 是在写入文件、更改所有者、权限或链接设置时随inode的内容更改而更改的。 因此,更改文件的内容即会更改mtime和ctime,但是文件的ctime可能会在 mtime 未发生任何变化时更改,例如,更改了文件的权限,但是文件内容没有变化。 如何获得一个文件的atime mtime 以及ctime ?

    ‘stat’ 命令可用来列出文件的 atime、ctime 和 mtime。

    [root@localhost ~]# find /etc/ -type f -mtime -1 -name "*.conf"   

    /etc/resolv.conf

    查找硬链接

    [root@localhost ~]# ln 1_heard.txt /tmp/1.txt.bak

    [root@localhost ~]# ls -l 1_heard.txt

    -rw-r--r--. 2 root root 0 12月 23 08:57 1_heard.txt

    [root@localhost ~]# ls -i 1_heard.txt

    67154010 1_heard.txt

    [root@localhost ~]# find / -inum 67154010

    /root/1_heard.txt

    /tmp/1.txt.bak

    查找一个小时以内的

    [root@localhost ~]# find /root/ -type f -mmin -60

    /root/1_heard.txt

    罗列详细信息

    [root@localhost ~]# find /root/ -type f -mmin -60 -exec ls -l {} \;

    -rw-r--r--. 2 root root 0 12月 23 08:57 /root/1_heard.txt

    查找出来,再改名

    [root@localhost ~]# find /root/ -type f -mmin -60 -exec mv {} {}.bak \;

    [root@localhost ~]# find /root/ -type f -mmin -60

    /root/1_heard.txt.bak

    查找root目录下,文件大小小于10k的文件,并列出详细信息

    [root@localhost ~]# find /root/ -type f -size -10k -exec ls -lh {} \;

    -rw-r--r--. 1 root root 18 12月 29 2013 /root/.bash_logout

    -rw-r--r--. 1 root root 176 12月 29 2013 /root/.bash_profile

    -rw-r--r--. 1 root root 176 12月 29 2013 /root/.bashrc

    -rw-r--r--. 1 root root 100 12月 29 2013 /root/.cshrc

    -rw-r--r--. 1 root root 129 12月 29 2013 /root/.tcshrc

    -rw-------. 1 root root 1.3K 10月 30 23:13 /root/anaconda-ks.cfg

    -rw-------. 1 root root 2.4K 12月 22 08:42 /root/.bash_history

    -rw-r--r--. 1 root root 381 12月 14 07:51 /root/.ssh/authorized_keys

    -rw-r--r--. 1 root root 172 12月 15 09:30 /root/.ssh/known_hosts

    -rwxrwxrwx. 1 hch1 hch 0 12月 20 08:36 /root/word1.txt

    -rw-r--r--. 1 root root 0 12月 20 08:37 /root/word2.txt

    -rw-r--r--. 1 root root 0 12月 20 08:44 /root/hello/1.txt

    -rw-r--r--. 1 root root 0 12月 20 08:44 /root/88/1.txt

    -rw-r--r--. 1 root root 20 12月 20 08:53 /root/dirb/filee

    -rw-r--r--. 1 hch1 root 0 12月 21 08:26 /root/hch/123.txt

    -rw-rw-r--. 1 root root 0 12月 21 08:26 /root/hch/1234.txt

    -rw-rw-r--. 1 root root 0 12月 21 08:28 /root/hch/456.txt

    -rw-rw-r--. 1 root root 0 12月 21 08:29 /root/hch/789.txt

    -rw-rw-r--. 1 root root 0 12月 21 08:21 /root/hch123.txt

    -rw-r--r--. 2 root root 0 12月 23 08:57 /root/1_heard.txt.bak

    Linux文件后缀名

    在linux系统中,文件的后缀名并没有具体意义,也就是说,你加或者不加,都无所谓。但是为了容易区分,我们习惯给文件加一个后缀名,这样当用户看到这个文件名时就会很快想到它到底是一个什么文件。例如1.sh, 2.tar.gz, my.cnf, test.zip等等,如果你首次接触这些文件,你也许会感到很晕,没有关系,随着学习的深入,你就会逐渐的了解这些文件了。阿铭所列举的几个文件名中1.sh代表它是一个shell script ,2.tar.gz 代表它是一个压缩包,my.cnf 代表它是一个配置文件,test.zip 代表它是一个压缩文件。

    另外需要你还需知道的是,早期Unix系统文件名最多允许14个字符,而新的Unix或者linux系统中,文件名最长可以到达 256 个字符!

    相关文章

      网友评论

          本文标题:find命令/文件名后缀

          本文链接:https://www.haomeiwen.com/subject/plyfgxtx.html