find命令的学习使用

来源:互联网 发布:php curl获取json数据 编辑:程序博客网 时间:2024/05/21 17:47
1.
     find . -print
     # 打印文件和目录的列表

2.   
find . -name "*.stackdump" | xargs rm
#查找后缀名为stackdump的文件并删除

3.
find . \( -name "*.hpp" -o -name "*.h" \) -print
#匹配多个条件,使用“OR”组合条件。以上命令查找后缀名为".hpp"与".h"的文件。

4.
find . -path "*tmp*" -print
#查找文件路径名以tmp结尾的的文件夹或文件

5.
find . -regex ".*\(\.py\|\.sh\)$"
#使用正则表达式模式查找文件

6.
find . ! -name "*.cpp" -print
#匹配所有不以.cpp结尾的文件名

7.
find . -maxdepth 1 -type d -print
#查找深度为1的目录(当前目录)下的所有文件类型为d(及文件夹)的文件并打印。

8.
find . -maxdepth 2 -name "*.cpp" -print
#查找深度为2的目录(当前目录的下一级目录)下所有后缀名为”.cpp“的文件并打印。

9.
find . -mindepth 2 -type f -print
#查找距离当前深度至少为2的文件并打印。


10.
find . -type l -print
#查找文件类型为符号链接类型的文件并打印。

11.
find . -type f -atime -7 -print
#查找最近7天被访问过的所有文件

12.
find . -type f -atime 7 -print
#查找恰好在七天前被访问的所有文件

13.
find . -type f -atime +7 -print
#打印出访问时间超过七天的所有文件


14.
find . -type f -amin -30 -print
#打印访问时间少于30分钟的所有文件

15.
find . -type f -size +20M
#查找当前目录下文件大小大于20MB的文件


16.
find . -type f -size -1k
#查找当前目录下文件大小小于1KB的文件

17.
find . -type f -size 4k
#查找当前目录下文件大小等于4KB的文件

文件大小:b-块,c-字节,w-字(2字节),k-千字节,M-兆字节,G-吉字节。

18.
find . -type f -name "*.swp" -delete
#删除当前目录下的所有.swp文件

19.
find . -type f -user frank -print
#查找文件所有者为frank的所有文件

20.
find . -type f -perm 644 -print
#查找文件权限为644的所有文件

21.
find . -type f -name "*.c" -exec cat {} \;>all_c_files.txt
#查找所有.c文件并拼接起来写入all_c_files.txt文件


22.
find . -type f -name "*.txt" -exec printf "Text file: %s\n" {} \;
#-exec能够同printf结合起来生成有用的输出信息。

23.
find . \( -name ".git" -prune \) -o \( -type f -print \)
#打印出不包含在.git目录下的所有文件的名称(路径)。



原创粉丝点击