Tuesday, June 23, 2015

How to check if a folder is empty in bash shell

Just use this following script:

if find /some/dir/ -maxdepth 0 -empty | read v; 
then 
       echo "Empty dir"
fi

Or to check not empty:

if ! find /some/dir/ -maxdepth 0 -empty | read v; ...