Linux通过find命令查找指定目录中的文件,是一个使用频率非常高的命令,本文详细讲述find命令各个参数及使用方法。

语法形式
| 1 | find path -option [ -print ] [ -exec | -ok command ] {} \; | 
语法说明
| 参数 | 说明 | 
| path | 指定查找路径 | 
| -option | 见“参数说明:-option” | 
| 将查找结果输出到标准输出 | |
| -exec | 将查找结果执行command操作,注意:{}和\;之间有空格 | 
| -ok | 将查找结果执行command操作前询问用户 | 
参数说明:-option
| 参数 | 说明 | 
| -name <filename> | 指定文件名称 | 
| -perm | 指定文件权限 | 
| -user <user> | 指定文件属主 | 
| -group <group> | 指定文件属组 | 
| -mtime -n / +n | 指定文件更改时间,-n:n天之内,+n:n天以前 | 
| -atime -n / +n | 指定文件访问时间,-n:n天之内,+n:n天以前 | 
| -ctime -n / +n | 指定文件创建时间,-n:n天之内,+n:n天以前 | 
| -nouser | 查找无属主文件,文件属主在/etc/passwd中不存在 | 
| -nogroup | 查找无属组文件,文件属组在/etc/groups中不存在 | 
| -newer f1 !f2 | 查找修改时间比f1新且比f2旧的文件 | 
| -type b/d/c/p/l/f | 类型:块设备/目录/字符设备/管道/符号链接/普通文件 | 
| -size n[c] | 查找长度为n块[或n字节]的文件 | 
| -depth | 在本目录查找完毕后再查找子目录 | 
| -fstype | 指定文件系统类型,在/etc/fstab中有描述 | 
| -mount | 不跨越文件系统mount点 | 
| -follow | 若遇到符号链接文件,则跟踪链接所指向的文件 | 
| -cpio | 将查找结果备份到磁带设备 | 
| -prune | 忽略指定目录 | 
示例
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | # 查找当前目录及子目并删除文件名以log为后缀的文件 find . -name "*.log" -exec rm -f {} \; # 查找/home目录中权限为700的文件和目录 find /home -perm 0700 # 在/mnt中查找名称为tom.txt且文件系统不为vfat的文件 find /mnt -name tom.txt ! -ftype vfat # 在/home中查找2天内被使用过的文件和目录 find /home -used -2 # 在/home中查找uid大于501的文件和目录 find /home -uid +501 # 在/home中查小于512k的文件 find /home -size -512k # 在/home中查硬连接数超过2的文件或目录 find /home -links +2 # 在根目录查找空文件和空文件夹 find / -empty | 
原创文章禁止转载:技术学堂 » Linux查找工具find使用方法详解

 技术学堂
技术学堂 
					















 
		