linux find -maxdepth 和xargs 用法

xargs
之所以能用到这个命令,关键是由于很多命令不支持|管道来传递参数,而日常工作中有有这个必要,所以就有了xargs命令,例如:

这个命令是错误的
find /sbin -perm +700 |ls -l

这样才是正确的

find /sbin -perm +700 |xargs ls -l   


mindepth 和 maxdepth

在root目录及其子目录下查找passwd文件。

1 # find / -name passwd
2 ./usr/share/doc/nss_ldap-253/pam.d/passwd
3 ./usr/bin/passwd
4 ./etc/pam.d/passwd
5 ./etc/passwd

在root目录及其1层深的子目录中查找passwd. (例如root — level 1, and one sub-directory — level 2)

1 # find -maxdepth 2 -name passwd
2 ./etc/passwd

在root目录下及其最大两层深度的子目录中查找passwd文件. (例如 root — level 1, and two sub-directories — level 2 and 3 )

1 # find / -maxdepth 3 -name passwd
2 ./usr/bin/passwd
3 ./etc/pam.d/passwd
4 ./etc/passwd

在第二层子目录和第四层子目录之间查找passwd文件。

扫描二维码关注公众号,回复: 1743446 查看本文章
1 # find -mindepth 3 -maxdepth 5 -name passwd
2 ./usr/bin/passwd
3 ./etc/pam.d/passwd


猜你喜欢

转载自blog.csdn.net/genziisme/article/details/78918495