将当前目录及子目录下,扩展名为c的文件列出:
find . -name “*.c”
.表示当前目录开始
查找文件1.txt:
find / -name “1.txt”
查找大小为4096bytes的文件:
find . -size 4096c
根据用户名查找:
find . -user root
find . -user “root”
按权限查找:
find . -perm 777
按文件属组查找:
find . -group group1
按类型查找:
find . -type b 块设备文件
find . -type D 目录
find . -type c 字符设备文件
find . -type p 管道文件
find . -type l 符号链接文件
find . -type f 普通文件
查找比file1新,比file2旧的文件:
find. -newer file1 ! file2
使用and:
find . -user root -and -name 1.txt
使用or:
find . -user root -or -name 1.txt
使用!
find . ! -name 1.txt
查找后显示文件信息:
find . ! -name 1.txt -ls
find . ! -name 1.txt | ls
查找后执行命令,在exec 后面跟命令,花括号,反斜线分号:
find . ! -name 1.txt -exec ls {} \;
find . ! -name 1.txt -exec rm {} \;
exec后面也可以跟shell脚本:
find . -name 1.txt -exec ./test.sh {} \;
或
find . -name 1.txt -exec |./test.sh
也可以使用ok代替exec,这样会询问使用允许操作:
find . ! -name 1.txt -ok ls {} \;
打印当前目录所有的文件:
find . -print
查找目录为两层,即当前和子目录:
find . -maxdepth -name “test.txt”
find . -maxdepth -name “test.txt”
在/apps目录下查找文件,但不在/apps/bin目录下查找:
find /apps -path “/apps/bin” -prune -o -print -name test.sh
如果同时使用了-depth选项,那么-prune选项就会被find命令忽略。
查找系统中最后5分钟访问的文件:
find . -amin -5
查找系统中最后5分钟以前访问的文件:
find . -amin +5
查找系统中最后n*24小时访问的文件:
find . -atime n
查找系统中最后N分钟被改变文件状态的文件:
find . -cmin n
查找系统中最后n*24小时被改变文件状态的文件:
find . -ctime n
查找系统中最后N分钟被改变文件数据的文件:
find . mmin n
查找系统中最后n*24小时被改变文件数据的文件:
find . -mtime n