Linux文件列表
参数说明:
-name 按照文件名字查找
*.txt 星号表示模糊匹配
libusb* 星号表示模糊匹配
-o or
-type c : 文件类型是 c 的文件。
d: 目录
c: 字型装置文件
b: 区块装置文件
p: 具名贮列
f: 一般文件
l: 符号连结
-ipath p, -path p : 路径名称符合 p 的文件,ipath 会忽略大小写
按文件名查找
find dir -name '*.txt'
dir 为句点表示 在当前目录下查找后缀为txt的所有文件(会搜索子目录)。
其中,点号.表示当前目录;-type f 表示查找的为文件。
find / -name mysql.sock
全盘搜索文件mysql.sock,这时候如果用 : find / -type f -name mysql.sock是搜索不到的。
在多个目录中查找
在两个目录/usr /bin 中查找文件名以libusb开头的文件
find /usr/ /bin/ -name 'libusb*'
按文件内容查找
在当前目录查找,查找文件内容,内部包含"clean"
find ./ -type f |xargs grep "clean"
排除指定目录
在根目录下搜索(除/mnt之外)g++文件
find / -path /mnt -prune -or -name g++
/mnt
/usr/share/doc/g++
/usr/share/bash-completion/completions/g++
/usr/bin/g++
排除多个目录
find . -type f -name "*config*" ! -path "./tmp/*" ! -path "./scripts/*" ! -path "./node_modules/*"
Explanation:
find . - Start find from current working directory (recursively by default)
-type f - Specify to find that you only want files in the results
-name "*_peaks.bed" - Look for files with the name ending in _peaks.bed
! -path "./tmp/*" - Exclude all results whose path starts with ./tmp/
! -path "./scripts/*" - Also exclude all results whose path starts with ./scripts/