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

后端 未结 7 854
無奈伤痛
無奈伤痛 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:43

    If you have files with extensions that don't match the file type, you could use the file utility.

    find $PWD -type f -exec file -N \{\} \; | grep "PDF document" | awk -F: '{print $1}'

    Instead of $PWD you can use the directory you want to start the search in. file prints even out he PDF version.

提交回复
热议问题