find命令
通用格式:find pathname -options [-print -exec -ok]
其中pathname中的“./”、“.”代表当前目录,“/”代表根目录,在表达式中出现的“{ }”代表find查找到的文件,
options选项如下:(表格来源:https://www.cnblogs.com/ftl1012/p/find.html)
表格补充:
补充:-print:将find命令查找到的结果输出,-exec cp {}:对find到的文件执行copy,-ok是exec的安全模式
文件名:
find /home/omd -type f -name "*a*" -print,在/home/omd下找名字中含有a的文件,并且输出展示(*代表n个字符)
find / -type d -name "[a-Z][0-9]" -print,在根目录下查找以一个字母和一个数字开头的文件并输出
权限:
find / -perm 777,查找权限为777的文件
find / -perm /u+r,find / -perm /g+w,find / -perm /o+x,find / -perm /a+r, u:user,g:group,o:others,a:all
find / -user user1name -or -user user2name查找在系统中属于user1name或着属于user2name的文件
find / -user user1name -and -user2name在系统中查找既属于user1name又属于user2name用户的文件.
组、用户:
find / -user root -name tecmint.txt 在根目录下找用户权限为root的tecmint.txt文件
find /home -group developer
修改时间:
*min单位是分钟,*time单位为小时,+多少时间以前,-指多少时间以内
find / -mtime +7 文件修改时间为7天以前的
find / -mtime 7 文件修改时间为第七天的
find / -mtime -7 文件修改时间为7天以内的
文件大小:
find / -size +100M 大于100M的文件
find / -size -100M 小于100M的文件
find / -size 100M 等于100M的文件
-exec结合使用(也可以用ok)(参考https://www.jb51.net/article/105267.htm)
-exec 参数后面跟的是command命令,它的终止是以“;”为结束标志的,后边可以跟“rm”、“cp”、“ls”等命令,注意“{}”与“\”之间留有空格,“\”与“;”之间不能有空格
find -name result.cap -type f -exec ls {} \; 查询完成后将文件列出来
-prune用法(参考:https://blog.csdn.net/u011517841/article/details/53204524)
find 的-prune可以在查找某目录下的某些文件时,避开某个目录,使用时注意:
1)-prune 必须和 -path, -o 一起使用
2)-prune -o 的顺序不 能调换
3)-name等必须放在-prune -o后面才能使用
eg: find . -path ./a -prune -o -name "*.txt" 去掉./a目录,加上txt文件 或: -path ./a -a -prune -o -name "*.txt",-a指and,-o指or,凡是-a与-prune连起来去掉,-o加上
find -path "live555" -a -prune -a -name "*.txt" -o -name "*.cap" -o -name "*mp4",去掉"live555" 、txt、cap文件,加上mp4文件
参考文件:https://www.cnblogs.com/ftl1012/p/find.html