Unix Shell – Check If Directory Is Empty

| Posted by watashii | Filed under Programming, Unix

Here is a simple unix shell command to check if a directory, $dir, is empty.

export $dir=/tmp/myfiles/
if [ "$(ls -A $dir)" ];
then
    echo "$dir NOT Empty";
else
    echo "$dir IS Empty";
fi

Share:

  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Print
  • email

Related Posts:

  1. UNIX file size listing – du command
  2. Unix LS Command With Colors… Without the —color Option
  3. Unix – Creating Cron Jobs with Crontab
  4. Unix ps command – Long Process Listing
  5. Oracle SQLPlus Query Output to a File

Tags: , , ,

Leave a Reply