[英]Creating a file with a list of paths (nested directories)
I have a set of nested directories in a tree-like structure, and every directory at the bottom of the tree contains another directory called "dump". 我在树状结构中有一组嵌套目录,并且树底部的每个目录都包含另一个名为“ dump”的目录。
I would like to create a file called "paths" with the all the paths to the "dump" directories, each one separated by a new line. 我想创建一个名为“ paths”的文件,其中包含“ dump”目录的所有路径,每个路径之间都用新行分隔。
My attempt is: 我的尝试是:
echo ./*/*/*/dump | cat >paths
This kind of works, but the paths are not separated by a new line. 这种工作,但是路径之间没有换行。 How can I achieve this, possibly using echo and cat?
如何使用echo和cat实现此目标?
将echo
与glob一起使用,并将其一次通过管道传送到xargs
( -n1
)并将其写入文件为
echo ./*/*/*/dump | xargs -n1 > file
You can use find
instead: 您可以改用
find
:
find . -type d -path '*/dump' > paths
or else just replace echo
by printf
in your glob
: 否则只需在您的
glob
中将printf
替换为echo
:
printf "%s\n" ./*/*/*/dump >paths
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.