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

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

    We had a similar question. We wanted a list - with paths - of all the config files in the etc directory. This worked:

    find /etc -type f \( -iname "*.conf" \)
    

    It gives a nice list of all the .conf file with their path. Output looks like:

    /etc/conf/server.conf
    

    But, we wanted to DO something with ALL those files, like grep those files to find a word, or setting, in all the files. So we use

    find /etc -type f \( -iname "*.conf" \) -print0 | xargs -0 grep -Hi "ServerName"
    

    to find via grep ALL the config files in /etc that contain a setting like "ServerName" Output looks like:

    /etc/conf/server.conf: ServerName "default-118_11_170_172"
    

    Hope you find it useful.

    Sid

    0 讨论(0)
提交回复
热议问题