shell 常用命令之二 find
一、find命令的功能是: 在指定路径下查找文件
二、find命令的基本格式:find [路径] [选项] [操作]
三、find 命令常用的选项:
name :根据文件名查找文件
perm :根据文件的权限查找文件
prune :可以使find命令不在当前指定的目录中查找
user :根据文件属主查找文件
group :根据文件所属的用户组查找文件
mtime -n +n : :根据文件更改的时间查找,-n 表示文件更改时间距今在n天之内,+n 表示文件更改时间距今在n天前
-newer file1 ! file2 :查找更改时间比文件file1新 但比文件file2 旧的文件
type (b:块设备文件,d:目录,c:字符设备文件,p:管道文件,l:符号链接文件,f:普通文件)
四、find命令操作名称
print :将匹配的文件输出到标准输出
exec:对匹配的文件执行该参数所给出的shell命令。相应命令形式为‘command’ {} ;。 //注意{}与;之间有空格
ok:与exec基本相同
五、举例
[root@zhangna ~]# find / -name "boot" #根据文件名查找是最常用的方式,/在根目录下查找 ./ 在当前目录下查找 /tmp 在这个目录下查找 /boot /usr/local/lib/anaconda-runtime/boot /usr/lib/anaconda-runtime/boot
[root@zhangna ~]# find /etc -type f -name "yum*" -exec ls -l {} ;
-rw-r--r--. 1 root root 0 9月 11 11:27 /etc/yum/yum.re
-rw-r--r--. 1 root root 10082 10月 16 2014 /etc/bash_completion.d/yum.bash
-rw-r--r--. 1 root root 8031 10月 15 2014 /etc/bash_completion.d/yum-utils.bash
-rw-r--r--. 1 root root 87 10月 16 2014 /etc/logrotate.d/yum
-rw-r--r--. 1 root root 969 10月 16 2014 /etc/yum.conf
