On Mon, Mar 31, 2003 at 01:40:18PM -0500, Jason Giangrande wrote: > Does anyone know how to check if a directory is empty? I tried the > following: > > if [ -d "/dir/to/remove" -a ! -s "/dir/to/remove" ]; then
Directories always have size > 0. [EMAIL PROTECTED]:mjinks$ mkdir foo [EMAIL PROTECTED]:mjinks$ ls -ld foo drwxr-xr-x 2 mjinks users 48 Mar 31 12:37 foo > Even if the directory (in this example "remove") is empty (has no other > files or folders) the else statement runs, which means the directory > does not get removed. Any suggestions would be much appreciated. There's probably a better way, but why not just use rmdir? It won't remove a directory with anything in it. -- Michael Jinks, IB # Enterprise Networks & Systems Administration # UofC Reader! Think not that technical information ought not be called speech; -- Anonymous, "How to decrypt a DVD" -- [EMAIL PROTECTED] mailing list