find的mindepth和maxdepth组合查找文件

find命令功能很多,参数也多,其中有两个参数mindepth和maxdepth搜索路径的最深和最浅深度,有的时候很有妙用! 

比如说要搜索: /root/config.xml的文件;同时在/root/AAA/config.xml,/root/AAA/BBB/config.xml, /root/AAA/BBB/CCC/config.xml....

如果只想查找/root/目录下的config.xml,就可以使用maxdepth和mindepth

$ find /root/ -maxdepth 2 -mindepth 2 'config.xml'
/root/config.xml

可谓非常简单! 可以省去很多麻烦。 

猜你喜欢

转载自blog.csdn.net/jerry_1126/article/details/81153401