Check empty directories and pick up command output

Asked

Viewed 466 times

1

I own a folder called work and inside it I have 2 folders: p1 and p2. How can I know if the folders p1 and p2 are empty ?

I have the following command

find . -type f -printf "%T@ %p\n" | sort -nr | cut -d\  -f2-

With this command I know if you have files inside the folders...then returns me in the terminal the folder and the file, if you have no files does not return anything.

How can I know what was the return? Example:

Se tem arquivo(s), print "Achou", senão print "Não achou".

2 answers

1


You need to put a if in command line. Would be next:

if [ `find . -type f | wc -l` -ge 1 ] ; then echo "Existe arquivos"; else echo "Nao existe arquivos"; fi
  • Show, thank you very much!

0

Or directly search for empty directories:

find . -type d -empty

Browser other questions tagged

You are not signed in. Login or sign up in order to post.