Linux中的find命令

一 语法

find [搜索范围] [搜索条件]
搜索文件
注意:
1、避免大范围搜索,会非常耗费系统资源。
2、find是在系统当中搜索符号条件的文件名。如果匹配,使用通配符匹配, 通配符匹配是完全匹配。
 
二 Linux中的通配符
          匹配任意内容
?          匹配任意一个字符
[]         匹配任意一个中括号的字符
 
三 举例
1、不区分大小写
find /root -iname install.log
2、按照所有者搜索
find /root -user root
3、查找没有所有者的文件(垃圾文件,/sys或/proc中的文件,外来文件如U盘)
find /root -nouser
4、根据事件查找文件
find /var/log -mtime +10
-10 10天内修改文件
10   10天当天修改的文件
+10 10天前修改的文件
atime 文件访问时间
ctime 改变文件属性
mtime 修改文件内容
5、按照大小搜索
find . -size 25k
查找文件大小是25KB的文件
-25k  小于25KB的文件
25k   等于25KB的文件
+25k 大于25KB的文件
6、根据i节点查找
find . -inum 26743
7、比较复杂的查找


 
 
四 实战
  1. [root@localhost ~]# find ChangeLog-2.6.0
  2. ChangeLog-2.6.0
  3. [root@localhost ~]# find -name "Cha*"
  4. ./ChangeLog-2.6.0
  5. [root@localhost test]# ls
  6. abc abcdef abc.soft
  7. [root@localhost test]# find -name "abc[d-f]"
  8. [root@localhost test]# find -name "abc[d-f]*"
  9. ./abcdef
  10. [root@localhost test]# find -user root
  11. .
  12. ./abc
  13. ./abc.soft
  14. ./abcdef
  15. [root@localhost test]# find -nouser
  16. [root@localhost test]# find -mtime -10
  17. .
  18. ./abc
  19. ./abc.soft
  20. ./abcdef
  21. [root@localhost test]# find .-size -25k
  22. .
  23. ./abc
  24. ./abc.soft
  25. ./abcdef
  26. [root@localhost test]# find .-size +1k
  27. [root@localhost test]# find .-size -1M
  28. ./abc
  29. ./abcdef
  30. ./1k
  31. [root@localhost test]# find .-size -1m
  32. find: invalid -size type `m'
  33. [root@localhost test]# find . -size -1K
  34. find: invalid -size type `K'
  35. [root@localhost test]# ls -i
  36. 67170464 1k 67170460 abc 67170463 abcdef 67170462 abc.soft
  37. [root@localhost test]#
  38. [root@localhost test]#
  39. [root@localhost test]#
  40. [root@localhost test]# find . -inum 67170463
  41. ./abcdef
  42. [root@localhost test]# find /etc -size +20k -a -size -50k
  43. /etc/selinux/targeted/modules/active/modules/apache.pp
  44. /etc/selinux/targeted/modules/active/modules/init.pp
  45. /etc/selinux/targeted/modules/active/modules/staff.pp
  46. /etc/selinux/targeted/modules/active/modules/sysadm.pp
  47. /etc/selinux/targeted/modules/active/modules/unprivuser.pp
  48. /etc/selinux/targeted/modules/active/modules/virt.pp
  49. /etc/selinux/targeted/modules/active/modules/xguest.pp
  50. /etc/selinux/targeted/modules/active/modules/xserver.pp
  51. /etc/sysconfig/network-scripts/network-functions-ipv6
  52. /etc/dnsmasq.conf
  53. /etc/brltty/fr-abrege.ctb
  54. /etc/brltty/de-kurzschrift.ctb
  55. /etc/brltty/en-nabcc.ttb
  56. /etc/brltty/en-us-g2.ctb
  57. /etc/brltty.conf
  58. /etc/postfix/access
  59. /etc/postfix/header_checks
  60. /etc/postfix/main.cf
  61. [root@localhost test]# find /etc -size +20k -a -size -50k -exec ls -lh {} \;
  62. -rw-r--r--. 1 root root 25K Nov 21 2015 /etc/selinux/targeted/modules/active/modules/apache.pp
  63. -rw-r--r--. 1 root root 29K Nov 21 2015 /etc/selinux/targeted/modules/active/modules/init.pp
  64. -rw-r--r--. 1 root root 34K Nov 21 2015 /etc/selinux/targeted/modules/active/modules/staff.pp
  65. -rw-r--r--. 1 root root 45K Nov 21 2015 /etc/selinux/targeted/modules/active/modules/sysadm.pp
  66. -rw-r--r--. 1 root root 29K Nov 21 2015 /etc/selinux/targeted/modules/active/modules/unprivuser.pp
  67. -rw-r--r--. 1 root root 27K Nov 21 2015 /etc/selinux/targeted/modules/active/modules/virt.pp
  68. -rw-r--r--. 1 root root 21K Nov 21 2015 /etc/selinux/targeted/modules/active/modules/xguest.pp
  69. -rw-r--r--. 1 root root 29K Nov 21 2015 /etc/selinux/targeted/modules/active/modules/xserver.pp
  70. -rw-r--r--. 1 root root 26K Sep 16 2015 /etc/sysconfig/network-scripts/network-functions-ipv6
  71. -rw-r--r--. 1 root root 25K Aug 6 2015 /etc/dnsmasq.conf
  72. -rw-r--r--. 1 root root 49K Mar 6 2015 /etc/brltty/fr-abrege.ctb
  73. -rw-r--r--. 1 root root 37K Mar 6 2015 /etc/brltty/de-kurzschrift.ctb
  74. -rw-r--r--. 1 root root 21K Mar 6 2015 /etc/brltty/en-nabcc.ttb
  75. -rw-r--r--. 1 root root 39K Mar 6 2015 /etc/brltty/en-us-g2.ctb
  76. -rw-r--r--. 1 root root 22K Mar 6 2015 /etc/brltty.conf
  77. -rw-r--r--. 1 root root 21K Jun 10 2014 /etc/postfix/access
  78. -rw-r--r--. 1 root root 22K Jun 10 2014 /etc/postfix/header_checks
  79. -rw-r--r--. 1 root root 27K Jun 10 2014 /etc/postfix/main.cf
  80. [root@localhost test]# find abc
  81. abc
  82. [root@localhost test]# find abc -exec rm -rf {} \;
  83. [root@localhost test]# find abc
  84. find: ?.bc?. No such file or directory

猜你喜欢

转载自cakin24.iteye.com/blog/2391229