user1960932
user1960932

Reputation:

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?

Upvotes: 1

Views: 5587

Answers (5)

Mohan Raj B
Mohan Raj B

Reputation: 1026

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

Example:

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

Upvotes: 0

Nishu Tayal
Nishu Tayal

Reputation: 20830

Try this :

find / -type f -name \*.txt

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

Upvotes: 2

oikku
oikku

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

Abdelbari Anouar
Abdelbari Anouar

Reputation: 246

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

Upvotes: 0

cdarke
cdarke

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

Related Questions