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

后端 未结 7 666
無奈伤痛
無奈伤痛 2021-01-31 15:26

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 th

7条回答
  •  时光取名叫无心
    2021-01-31 15:44

    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.

提交回复
热议问题