简体   繁体   中英

linux include all directories

how would I type a file path in ubuntu terminal to include all files in all sub-directories?

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/???

From within the books top directory, you can use the command:

find . -type f

Then, if you wanted to, say run each file through cat, you could use the xargs command:

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':

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. You can choose whatever command you want to run on the files you get shell-expanded. Also note that directories will also be included (if not excluded by name, eg *.png or *.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 . See also this tutorial on shell expansion .

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 ).

I also like find very much. It's quite easy to generate more flexible search patterns in combination with grep . To provide a random example:

du `find . | grep some_pattern_to_occur | grep -v some_pattern_to_not_occur`

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM