Reputation:
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?
Upvotes: 1
Views: 5587
Reputation: 1026
ls -R path_of_your_directory | grep "\.txt$"
Example:
ls -R /tmp | grep "\.txt$"
Upvotes: 0
Reputation: 20830
Try this :
find / -type f -name \*.txt
It will give you all .txt files in '/' directory.
Upvotes: 2
Reputation: 562
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.
Upvotes: 2
Reputation: 44344
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
Upvotes: 1