find命令简单用法
2016-05-10 22:44
441 查看
//递归查找当前文件下后缀为.txt的文件
find ./ -iname '*.txt'
//查找当前文件下后缀为txt的文件(不递归)
find ./ -maxdepth 1 -iname "*.txt"
//或用法,查找当前目录以及子目录下所有txt文件或是pdf文件
find ./ -iname “*.txt” -o -iname "*.pdf"
//非用法(not),查找所有非txt文件
find ./ ! -iname "*.txt"
//与用法
find ./ -name "hello*" -and "*.txt" //以hello开头,以.txt结尾
更多用法:
http://blog.chinaunix.net/uid-20082146-id-83489.html
使用-size选项可以通过文件大小查找文件。
//列举大于100M的文件
find ./ -type f -size +100M
//列举等于100M的文件find ./ -type f -size 100M//列举小于100M的文件find ./ -type f -size -100M
排除特定目录搜索 (-prune)//在/apps目录下查找文件,但忽略目录/apps/bin。find /apps -path "/apps/bin" -prune -o -type f -name "*.pdf" -print
注:上面的命令可以这样进行理解:find /apps -path "apps/bin" --> 返回apps/bin,其实就是查找apps/bin目录
find /apps -path "apps/bin" -prune --> 返回除apps/bin的目录,加prune就是排除前面的目录。
find /apps -path "apps/bin" -prune -o -print --> 当查找到apps/bin时,find返回true(找到了-path指定的目录),然后被prune接管,因为前面已经是true了,那么-o print(或命令)就无须执行了,那么print就被忽略了。当查找到非apps/bin时,find返回false,然后执行-prune -o -print,因为前面返回false,-prune返回也是false,所以-print会执行,也就能输出显示了。
(通俗的可以这样理解:查找apps,如果是apps/bin,那么忽略(prune),否则(or)输出print)。
如果要忽略两个以上的路径如何处理?find /apps \( -path "/apps/bin" -o -path "/apps/xbin" \) -prune -o -type f -printfind . \( -path "./bin" -o -path "./xbin" \) -prune -o -type f -name "*.pdf" -print注意/( 和/) 前后都有空格,注意当前路径下的目录要加上./。
find ./ -iname '*.txt'
//查找当前文件下后缀为txt的文件(不递归)
find ./ -maxdepth 1 -iname "*.txt"
//或用法,查找当前目录以及子目录下所有txt文件或是pdf文件
find ./ -iname “*.txt” -o -iname "*.pdf"
//非用法(not),查找所有非txt文件
find ./ ! -iname "*.txt"
//与用法
find ./ -name "hello*" -and "*.txt" //以hello开头,以.txt结尾
更多用法:
http://blog.chinaunix.net/uid-20082146-id-83489.html
使用-size选项可以通过文件大小查找文件。
//列举大于100M的文件
find ./ -type f -size +100M
//列举等于100M的文件find ./ -type f -size 100M//列举小于100M的文件find ./ -type f -size -100M
排除特定目录搜索 (-prune)//在/apps目录下查找文件,但忽略目录/apps/bin。find /apps -path "/apps/bin" -prune -o -type f -name "*.pdf" -print
注:上面的命令可以这样进行理解:find /apps -path "apps/bin" --> 返回apps/bin,其实就是查找apps/bin目录
find /apps -path "apps/bin" -prune --> 返回除apps/bin的目录,加prune就是排除前面的目录。
find /apps -path "apps/bin" -prune -o -print --> 当查找到apps/bin时,find返回true(找到了-path指定的目录),然后被prune接管,因为前面已经是true了,那么-o print(或命令)就无须执行了,那么print就被忽略了。当查找到非apps/bin时,find返回false,然后执行-prune -o -print,因为前面返回false,-prune返回也是false,所以-print会执行,也就能输出显示了。
(通俗的可以这样理解:查找apps,如果是apps/bin,那么忽略(prune),否则(or)输出print)。
如果要忽略两个以上的路径如何处理?find /apps \( -path "/apps/bin" -o -path "/apps/xbin" \) -prune -o -type f -printfind . \( -path "./bin" -o -path "./xbin" \) -prune -o -type f -name "*.pdf" -print注意/( 和/) 前后都有空格,注意当前路径下的目录要加上./。
相关文章推荐
- Linux socket 初步
- Linux Kernel 4.0 RC5 发布!
- linux lsof详解
- linux 文件权限
- Linux 执行数学运算
- 10 篇对初学者和专家都有用的 Linux 命令教程
- Linux 与 Windows 对UNICODE 的处理方式
- Ubuntu12.04下QQ完美走起啊!走起啊!有木有啊!
- 解決Linux下Android开发真机调试设备不被识别问题
- 运维入门
- 运维提升
- Linux 自检和 SystemTap
- Ubuntu Linux使用体验
- c语言实现hashmap(转载)
- Linux 信号signal处理机制
- linux下mysql添加用户
- Scientific Linux 5.5 图形安装教程
- Linux 下无损图片压缩小工具介绍