find <path> -iname <file_name> -exec <action> {} [argument] \;
例:
1、当前目录查找txt文件复制到/tmp下
# find ./ -iname \*.txt -exec cp {} /tmp/ \;
2、删除当前目录下4天前的txt文件
# find ./ -iname \*.txt -mtime +4 -exec rm -rf {} \;
find报错:
[root@puppet test]# find ./ -iname *.txt 
find: paths must precede expression: 2.txt
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
原因:若查找到的文件不止一个会出现这种问题
解决:对*加\转义或者对查找的内容加引号
[root@puppet test]# find ./ -iname \*.txt 
./3.txt
./4.txt
./2.txt
./1.txt
[root@puppet test]# find ./ -iname '*.txt'
./3.txt
./4.txt
./2.txt
./1.txt
[root@puppet test]# find ./ -iname "*.txt"
./3.txt
./4.txt
./2.txt
./1.txt