简体   繁体   中英

How to list the files inside directory and sub directories?

I have a directory and in that there are sub-directories that have text files,now i want to list all the .txt files in the sub-directories with path. how to do this?

Use find command

find /where/to/search -name "*.txt" -type f

That will list only files ending .txt. Using -type f it won't list directory even if it's name happens to end with .txt.

Try this :

find / -type f -name \*.txt

It will give you all .txt files in '/' directory.

Several ways:

echo directory_name/*/*.txt

is probably the most efficient: echo is a shell built-in, and the * expansion is done by bash . If you need more power, use ls instead of echo

Try This One : tree -R | grep ".txt" tree -R | grep ".txt"

ls -R path_of_your_directory | grep "\.txt$"

例:

ls -R /tmp | grep "\.txt$"

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