Let's say I want to list all the php files in a directory, including subdirectories, I can run this in bash:
ls -l $(find. -name *.php -type f)
The problem is that if there are no php files at all, the command that runs, ls -l , lists all the files and directories, not 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 ultimately returns the size of all records if there are no files matching the *.php pattern.
How can I protect myself from this event?
bash find
xbonez
source share