Archive for August 8th, 2014

is that directory empty?

I needed a quick and dirty way to find if the contents of a directory is empty. I’m not interested in th hidden files only files or orther directories within. Here is the bash script i knocked up to do the check…

#!/bin/bash
DIRECTORY=“/SOMEWHERE/”
if[ “$(ls -A $DIRECTORY)”]; then
echo”$DIRECTORY is not empty!”
else
echo”$DIRECTORY is empty!”
fi
exit

Job done.

August 8, 2014 | By | Reply More