Check If the Directory Folder Is Empty

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

Have a Unix Problem
Unix Forum - Do you have a UNIX Question?

Unix Books :-
UNIX Programming, Certification, System Administration, Performance Tuning Reference Books

Return to : - Unix System Administration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.
The site www.gotothings.com is in no way affiliated with or endorsed by any company listed at this site.
Any unauthorised copying or mirroring is prohibited.