Fropper.com - no one's a stranger
Already a member? Login here  | Tour | Help  
in


php tips and tacts n some unseen functions yet powerfull.....



Posted on: Nov 05, '08


 how to check the empty directory in shell script

How to check the empty directory in shell script?

This can be easily done with the help ls command.
we can simply check the empty directory using following script.

DIR="/path/to/directory/"

if [ "$(ls -A $DIR)" ]; then
           echo "Take action $DIR is not Empty"
else
           echo "$DIR is Empty"

You can also assign the output of specific command to a separate variable instead of checking it directly in if condition.
e.g.

myVar=`(grep 'stringToSearch' filename.ext)`;

Note: Do not use spaces before and after =.



Tags: php, shell, shell script, linux




Comments  [ 0 Comments ] [ Post your comment | Subscribe (?) ]

No comment received.
Want to comment on this post?

Register now, its FREE, and share your views.
Already a member? Login now.