Linux下的文件查找命令


Linux的五个文件查找命令:find,locate,whereis,which,type

find:查找文件或目录所在路径

  1. 格式:find [路径] [表达式]
  2. 表达式:
  3. -name :查找名为filename的文件
  4. -perm :按执行权限来查找
  5. -empty :查找空文件或空目录
  6. -user :按文件属主来查找
  7. -group :按组来查找
  8. -nogroup :查无有效属组的文件,即文件的属组在/etc/groups中不存在
  9. -nouser :查无有效属主的文件,即文件的属主在/etc/passwd中不存
  10. -mtime :按文件更改时间来查找文件
  11. -atime :按文件访问时间来查找文件
  12. -ctime :按文件创建时间来查找文件
  13. -newer :查更改时间更新的文件或目录
  14. -type :查是块设备b、目录d、字符设备c、管道p、符号链接l、普通文件f
  15. -size n[c] :查找大小为n块(512字节)[或n字节]的文件
  16. -inum :根据i节点查找
  17. -depth :使查找在进入子目录前先行查找完本目录
  18. -fstype :查位于某一类型文件系统中的文件,这些文件系统类型通常可 在/etc/fstab中找到
  19. -mount :查文件时不跨越文件系统mount点
  20. -cpio :对匹配的文件使用cpio命令,将他们备份到磁带设备中
  21. -prune :忽略某个目录
  22. -maxdepth :查询的目录深度
  23. -exec :查找文件并执行后面的命令 find ... -exec CMD {} \;
  24. -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、mmin c--change表示文件的属性被修改过 a--access m--modify表示文件的内容被修改过 +n表示n天以前 -n表示n天以内  
  1. [root@rhel6 ~]# find /etc/ -name "host*" "查询/etc/目录(包括子目录)中以host开头的文件或目录"
  2. [root@rhel6 ~]# find -type l "查询当前目录下文件类型为链接的文件"
  3. [root@rhel6 ~]# find -size +10000000c "查询当前目录中>10M的文件"
  4. [root@rhel6 ~]# find -size -1K "查询当前目录中<1K的文件"
  5. [root@rhel6 ~]# find /etc -name inittab -o -size +17M "查询/etc/目录中文件名为inittab或文件>17M的文件"
  6. [root@rhel6 ~]# find /etc -name "*.conf" [-a] -size +20k "查询/etc/目录中文件名为*.conf且文件<20k的文件"
  7. [root@rhel6 ~]# find /etc/* -name "*.conf" -not -name "*http*" "查询/etc目录中文件名为*.conf但不包含http的文件"
  8. [root@rhel6 ~]# find /etc/ -empty "查询/etc/目录中的空文件或空目录"
  9. [root@rhel6 ~]# find /var -user Oracle "查询/var/目录中属于用户oracle的文件或目录"
  10. [root@rhel6 ~]# find /home -group xfcy
  11. [root@rhel6 ~]# find -inum 1024 "查询当前目录中 i 节点为1024的文件或目录"
  12. [root@rhel6 ~]# find -newer new "查询当前目录中比文件new还新的文件或目录"
  13. [root@rhel6 ~]# find /etc/ -nouser -o -nogroup "查询/etc/目录中不属于本地用户的文件或目录(危险文件)"
  14. [root@rhel6 ~]# find /data/ -mmin -10 "查询/data/目录中十分钟内文件内容被修改过的文件"
  15. [root@rhel6 ~]# find /proc/ -type f -maxdepth 1 "查询/data/目录中文件类型为普通文件的文件且不查询子目录"
  16. [root@rhel6 ~]# find /data/ -mtime -10 -exec rm {} \; "查询/data/目录中十分钟内内容被修改过的文件并将其删除"
  17. [root@rhel6 ~]# find /data/ -mtime -10 -ok rm {} \; "查询/data/目录中十分钟内内容被修改过的文件并询问是否将其删除(y/n)"
  • 1
  • 2
  • 下一页

相关内容

    暂无相关文章