Kumar Alok Kumar Alok - 1 year ago 43
Bash Question

How to list specific type of files in recursive directories in shell?

How can we find specific type of files i.e. doc pdf files present in nested directories.

command I tried:

$ ls -R | grep .doc

but if there is a file name like
the command will display that too which is obviously not what I want. What command should I use instead?

Answer Source

If you are more confortable with "ls" and "grep", you can do what you want using a regular expression in the grep command (the ending '$' character indicates that .doc must be at the end of the line. That will exclude "file.doc.txt"):

ls -R |grep .doc$

More information about using grep with regular expressions in the man.