[英]linux include all directories
how would I type a file path in ubuntu terminal to include all files in all sub-directories? 如何在ubuntu终端中键入文件路径以将所有文件包含在所有子目录中?
If I had a main directory called "books" but had a ton of subdirectories with all sorts of different names containing files, how would I type a path to include all files in all subdirectories? 如果我有一个名为“ books”的主目录,但有大量的子目录,其中的各种名称包含文件,那么我该如何键入一个路径以在所有子目录中包含所有文件?
/books/??? /图书/???
From within the books top directory, you can use the command: 在books顶层目录中,可以使用以下命令:
find . -type f
Then, if you wanted to, say run each file through cat, you could use the xargs command: 然后,如果您希望通过cat运行每个文件,则可以使用xargs命令:
find . -type f | xargs cat
For more info, use commands: 有关更多信息,请使用命令:
man find
man xargs
./books/*
For example, assuming i'm in the parent directory of 'books': 例如,假设我在“ books”的父目录中:
ls ./books/*
EDIT: 编辑:
Actually, to list all the tree recursively you should use: 实际上,要递归列出所有树,应使用:
ls -R ./books/*
It is unclear what you actually want ... Probably you will get a better solution to your problem, if you ask directly for it, not for one other problem you've come accross trying to circumvent the original problem. 目前尚不清楚您真正想要的是什么...如果您直接提出要求,而不是针对另一个问题,而您试图绕过原始问题,可能会得到更好的解决方案。
do you mean something like the following? 您是说类似以下内容吗?
file */*
where the first *
expands for all subdirectories and the second *
for all contained files ? 其中第一个
*
扩展为所有子目录和第二*
所有包含的文件?
I have chosen the file
command arbitrarily. 我已经任意选择了
file
命令。 You can choose whatever command you want to run on the files you get shell-expanded. 您可以选择任何要在经过Shell扩展的文件上运行的命令。 Also note that directories will also be included (if not excluded by name, eg
*.png
or *.txt
). 另请注意,目录也将包括在内(如果未按名称排除,例如
*.png
或*.txt
)。 The wildcard *
is not exactly the file path to include all files in all subdirectories but it expands to all files (or directories) matching the wildcard expression as a list, eg file1 file2 file3 file4
. 通配符
*
并非是要包含所有子目录中所有文件的文件路径,但它会扩展为与通配符表达式匹配的所有文件(或目录)为列表,例如file1 file2 file3 file4
。 See also this tutorial on shell expansion . 另请参阅有关shell扩展的本教程 。
Note that there may be easy solutions to related problems. 请注意,对于相关问题可能有简单的解决方案。 Like to copy all files in all subdirectories (
cp -a
for example, see man cp
). 喜欢复制所有子目录中的所有文件(例如
cp -a
,请参见man cp
)。
I also like find
very much. 我也想
find
非常多。 It's quite easy to generate more flexible search patterns in combination with grep
. 与
grep
结合生成更灵活的搜索模式非常容易。 To provide a random example: 提供一个随机示例:
du `find . | grep some_pattern_to_occur | grep -v some_pattern_to_not_occur`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.