考虑以下文件夹结构
root/dirA/the_folder
root/dirA/dir2/the_folder
root/dirB/the_folder
root/dirB/dir2/the_folder
我想以dirA/the_folder
和dirB/the_folder
递归查找并定位。但是当我使用
find root/ -name 'the_folder' -type d | xargs tar cvf myTar.tar
它将打包所有文件夹(包含dir2 / the_folder),我不希望这样。解决方案是什么?
答案 0 :(得分:3)
使用-maxdepth
的{{1}}选项限制递归深度:
find
对find root/ -maxdepth 2 -name 'the_folder' -type d
提供的有用选项 lot ,请man find
。你会感到惊讶。例如,您可以使用find
的{{1}}选项取消| xargs
:
find
答案 1 :(得分:3)
在你的情况下,这不仅仅是这个吗?
tar cfv mytar.tar root/*/the_folder/