Want to know if exist a function that controls if a folder in unix system is empty or not.
What means "control"? - perhaps " a way to test if a directory is empty"?
Yes, I have to check if the directory is empty.
I'm assuming you want a script function. This works with ksh:
listfiles() { ls -1 ${1:+"$@"} 2>/dev/null; }
is_dir_empty()
{ test ! -d $1 -o -z "$(listfiles -A $1)";}
# here's how if can be used: execute the chmod command only if there's something in the directory:
dirobj="/tmp/mydir"
is_dir_empty $dirobj && echo $dirobj is empty || chmod 666
$dirobj
Quick Links:
Do you have
a UNIX Question?
Unix Home: Unix System Administration
Hints and Tips