01.find命令介绍
**更多详细内容参考:**https://www.cnblogs.com/xiaonq/p/11969744.html
1.1 find作用
Linux find命令用来在指定目录下查找文件。
任何位于参数之前的字符串都将被视为欲查找的目录名。
如果使用该命令时,不设置任何参数,则find命令将在当前目录下查找子目录与文件。
1.2 find常用参数
选项
含义
-name
根据文件名称查找
-size -n +n
根据文件大小查找
-mtime -n
根据文件修改时间查找
-type
根据文件类型查找
-perm
根据文件权限查找
1.3 find参数基本使用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 find /etc -name '*.conf' find . -size +9M find . -size -1M find /etc -mtime -5 -name '*.conf' find /etc -mtime +5 -name '*.conf' find /etc -mmin +30 find /etc -mmin -30 find . -type f find . -type d find . -user yangyang find . -group yangyang find /etc -perm 664
02.find应用
2.1 大于9M的文件
1. find . -size +9M | xargs ls -lh : 查找当前目录下大于9M的文件详细信息
1 2 3 4 5 6 7 8 [root@linux-node1 /] -rw-r--r-- 1 root root 24M Jul 7 04:18 ./aaa/Python-3.7 .0 /libpython3.7 m.a -rwxr-xr-x 1 root root 14M Jul 7 04:19 ./aaa/Python-3.7 .0 /Programs/_testembed -rwxr-xr-x 1 root root 14M Jul 7 04:18 ./aaa/Python-3.7 .0 /python -rw-r--r-- 1 root root 22M Jul 6 23 :53 ./aaa/Python-3.7 .0 .tgz -rw-------. 1 root root 47M Jan 7 2019 ./boot/initramfs-0 -rescue-8b956f09fe0549c4b6182589acceab30.img -rw-------. 1 root root 21M Jan 7 2019 ./boot/initramfs-3.10 .0 -514. el7.x86_64.img -rw-------. 1 root root 14M Jan 7 2019 ./boot/initramfs-3.10 .0 -514. el7.x86_64kdump.img
2.2 以 .log 结尾且大于5M的文件
2. find . -type f -name “*.log” -size +1M -exec cp -av {} /tmp ;
查找当前目录下以 .log 结尾且大于5M的文件,并复制到/tmp目录下
1 2 3 [root@linux-node1 /] cp: ‘./tmp/audit.log’ and ‘/tmp/audit.log’ are the same file cp: ‘./tmp/journal.log’ and ‘/tmp/journal.log’ are the same file
2.3 更改时间在三天到五天的文件
3. find /var -mtime +3 -mtime -5 :在/var下查找更改时间在三天到五天的文件
1 2 3 4 [root@linux-node1 /] /var/tmp /var/lib/yum/yumdb/l /var/lib/yum/yumdb/l/f20daac8f6b3893e42be72af22a5118848f
2.4 1分钟前3分钟内修改的文件
4. find . -mmin +1 -mmin -3 :查找当前文件夹下1分钟前3分钟内修改的文件
1 2 [root@linux-node1 /] ./aa.py
__END__