Linux的五个文件查找命令:find,locate,whereis,which,type
find:查找文件或目录所在路径
- 格式:find [路径] [表达式]
- 表达式:
- -name:查找名为filename的文件
- -perm:按执行权限来查找
- -empty :查找空文件或空目录
- -user:按文件属主来查找
- -group :按组来查找
- -nogroup :查无有效属组的文件,即文件的属组在/etc/groups中不存在
- -nouser:查无有效属主的文件,即文件的属主在/etc/passwd中不存
- -mtime :按文件更改时间来查找文件
- -atime :按文件访问时间来查找文件
- -ctime :按文件创建时间来查找文件
- -newer :查更改时间更新的文件或目录
- -type:查是块设备b、目录d、字符设备c、管道p、符号链接l、普通文件f
- -size n[c] :查找大小为n块(512字节)[或n字节]的文件
- -inum:根据i节点查找
- -depth :使查找在进入子目录前先行查找完本目录
- -fstype:查位于某一类型文件系统中的文件,这些文件系统类型通常可 在/etc/fstab中找到
- -mount :查文件时不跨越文件系统mount点
- -cpio:对匹配的文件使用cpio命令,将他们备份到磁带设备中
- -prune :忽略某个目录
- -maxdepth:查询的目录深度
-
- -exec :查找文件并执行后面的命令 find ... -exec CMD {} ;
- -ok :询问是否要执行后面的命令 find ... -ok CMD {} ;
-perm mode表示严格匹配-perm -mode 表示mode中转换成二进制的1必须
全部匹配(不管0位) -perm +mode 表示mode中转换成二进制的1必须
部分匹配(不管0位) -ctime/atime/mtime/cmin/amin/mmin:按时间查找以天为单位的:ctime、atime、mtime以分钟为单位的:cmin、amin、mminc--change表示文件的属性被修改过a--accessm--modify表示文件的内容被修改过+n表示n天以前-n表示n天以内
- [root@rhel6 ~]# find /etc/ -name "host*" "查询/etc/目录(包括子目录)中以host开头的文件或目录"
- [root@rhel6 ~]# find -type l "查询当前目录下文件类型为链接的文件"
- [root@rhel6 ~]# find -size +10000000c"查询当前目录中>10M的文件"
- [root@rhel6 ~]# find -size -1K "查询当前目录中<1K的文件"
- [root@rhel6 ~]# find /etc -name inittab -o -size +17M"查询/etc/目录中文件名为inittab或文件>17M的文件"
- [root@rhel6 ~]# find /etc -name "*.conf" [-a] -size +20k "查询/etc/目录中文件名为*.conf且文件<20k的文件"
- [root@rhel6 ~]# find /etc/* -name "*.conf" -not -name "*http*""查询/etc目录中文件名为*.conf但不包含http的文件"
- [root@rhel6 ~]# find /etc/ -empty"查询/etc/目录中的空文件或空目录"
- [root@rhel6 ~]# find /var -user Oracle "查询/var/目录中属于用户oracle的文件或目录"
- [root@rhel6 ~]# find /home -group xfcy
- [root@rhel6 ~]# find -inum 1024"查询当前目录中 i 节点为1024的文件或目录"
- [root@rhel6 ~]# find -newer new"查询当前目录中比文件new还新的文件或目录"
- [root@rhel6 ~]# find /etc/ -nouser -o -nogroup "查询/etc/目录中不属于本地用户的文件或目录(危险文件)"
- [root@rhel6 ~]# find /data/ -mmin -10"查询/data/目录中十分钟内文件内容被修改过的文件"
- [root@rhel6 ~]# find /proc/ -type f -maxdepth 1"查询/data/目录中文件类型为普通文件的文件且不查询子目录"
-
- [root@rhel6 ~]# find /data/ -mtime -10 -exec rm {} ;"查询/data/目录中十分钟内内容被修改过的文件并将其删除"
- [root@rhel6 ~]# find /data/ -mtime -10 -ok rm {} ;"查询/data/目录中十分钟内内容被修改过的文件并询问是否将其删除(y/n)"
Linux下的高级文件权限ACLDHCP+TFTP+PXE自动网络引导安装Linux操作系统相关资讯 Linux下的查找命令 Linux的查找命令 本文评论 查看全部评论 (0)