3

find命令的一点注意事项

 2 years ago
source link: https://blogread.cn/it/article/2728?f=hot1
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

find命令的一点注意事项

浏览:2848次  出处信息

其实也不是find命令的问题,以前总写不对find命令,今天才发现原因在哪里了。

     如果文件不够多我们也不使用find命令;    find命令的结果是文件名,要想知道自己find的结果是否正确,一般管道输出给ls    于是命令很容易写成: find .... | ls -lh    结果看到的总是目录内的所有内容,似乎是find失效,为什么呢?    命令应该写成: find ... | xargs ls -lh    看到了吧,就一个xargs只差,把所有的罪过都错给了find命令了

    下面写几个find命令已做纪念:

     查找大于30k,并且小于30M的文件:ffind . -type f -size +30k -size -30M |xargs ls -lh

     size的单位有: cbkMG , 里面的“k”是小写的,M、G是大写的    两个size条件之间是“并且”的关系,如果需要“或”关系,可以使用 “-or” 链接两个条件    查找小于30k,或者大于30M的文件:find . -type f -size -30k -or -size +30M |xargs ls -lh

     查找小于30k,或者大于30M,或者文件名以“abc”开头的文件:find . -type f -size -30k -or -size +30M -name  -or "abc*" |xargs ls -lh

     查找小于30k,或者大于30M,并且文件名以“abc”开头的文件:find . -type f -size -30k -or -size +30M -name  "abc*" |xargs ls -lh

     “-or”命令只对后面的一个过滤器有效

建议继续学习:

QQ技术交流群:445447336,欢迎加入!
扫一扫订阅我的微信号:IT技术博客大学习

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK