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)
The problem with this is that if there are no php
files at all, the command that gets executed is ls -l
, listing all files and directories, instead of none.
This is a problem, because I'm trying to get the combined size of all php
files using
ls -l $(find . -name *.php -type f) | awk '{s+=$5} END {print s}'
which ends up returning the size of all entries in the event that there are no files matching the *.php
pattern.
How can I guard against this event?