List all files in a directory with a certain extension

后端 未结 3 1918
伪装坚强ぢ
伪装坚强ぢ 2021-01-11 18:34

Let\'s say I want to list all php files in a directory including sub-directories, I can run this in bash:

ls -l $(find. -name *.php -type f)

相关标签:
3条回答
  • 2021-01-11 18:58

    Here is another way, using du:

    find . -name "*.php" -type f -print0 | du -c --files0-from=- | awk 'END{print $1}'
    
    0 讨论(0)
  • 2021-01-11 19:07

    If you want to avoid parsing ls to get the total size, you could say:

    find . -type f -name "*.php" -printf "%s\n" | paste -sd+ | bc
    
    0 讨论(0)
  • 2021-01-11 19:18

    I suggest you to firstly search the files and then perform the ls -l (or whatever else). For example like this:

    find . -name "*php" -type f -exec ls -l {} \;
    

    and then you can pipe the awk expression to make the addition.

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