linux 常用find命令

1、查找当前目录下以test开头的所有文件-会进入子目录中去查找

[root@rusky hgfs]# find -name test*

2、查找当前目录下名为test.txt的文件-会进入子目录中去查找

[root@rusky hgfs]# find -name test.txt  

3、在指定路径/mnt  中查找以fuck开头的所有文件或目录,或去掉*号,查找名为fuck的文件或目录

[root@rusky /]# find /mnt -name fuck*  

4、查找名为fu?k的文件或目录,?号表示第三个字符为任意。如,fuabk就不显示。要查找fuabk,则可用fu??k或fu*k 

[root@rusky /]# find /mnt -name fu?k
/mnt/hgfs/SHARE/fubk
/mnt/hgfs/SHARE/testdir2/fuck

[root@rusky /]# find /mnt -name fu*k
/mnt/hgfs/SHARE/fuabk
/mnt/hgfs/SHARE/fubk
/mnt/hgfs/SHARE/testdir2/fuck

5、到多个路径下查找后缀名为.zip文件,注意" "或路径在find之后  

find /home /mnt -name  "*.zip"

6、只在当前目录下查找 -maxdepth 1   

[root@rusky SHARE]# find -maxdepth 1 -name "fuck*"
./fuck.tar.gz
./fuck.zip
[root@rusky SHARE]# find -maxdepth 2 -name "fuck*"
./fuck.tar.gz
./fuck.zip
./testdir2/fuck

 7、关于查找文件,还有另外一个命令:locate filename

8、其它

[root@rhel7 sbin]# pwd
/sbin
[root@rhel7 sbin]# find -name rt*
find: paths must precede expression: rtcwake
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
[root@rhel7 sbin]# find -name "rt*"
./rtmon
./rtpr
./rtcwake
./rtacct
./rtstat
[root@rhel7 sbin]# 

-delete可以用来删除find查找到的匹配文件。
删除当前目录下所有的 .swp文件:
$ find . -type f -name "*.swp" -delete

打印出用户rusky拥有的所有文件:
$ find . -type f -user rusky

-type可以对文件搜索进行过滤。借助这个选项,我们可以为find命令指明特定的文件匹配
类型。
只列出所有的目录:
$ find . -type d -print
将文件和目录分别列出可不是个容易事。不过有了find就好办了。例如,只列出普通文件:
$ find . -type f -print
只列出符号链接:
$ find . -type l -print

原文地址:https://www.cnblogs.com/rusking/p/3631984.html