[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Check if dir is empty



Kevin B. McCarty, 

> > Yes, but I need a script to act if there are files in a directory.
> 
> if [ -n "$(ls -A "$directory")" ] ; then
> 	# do something
> fi
> 
> n.b. I suspect "ls -A" is a GNU extension, so probably is not portable.
>  Also the test will give a false negative if the directory does not have
> read permission.

But if a directory-tree is full of files, but no-one's around to see
them, does it then have files? ;)

-- 
regards,

Christopher Pharo Glæserud



Reply to: