Check empty directories and catch command output

1

I have a folder called work and inside it I have 2 folders: p1 and p2 . How can I tell if the p1 and p2 folders 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 there are files inside the folders ... then the folder and file will return in the terminal, if it has no files it will not return anything.

How do I know what the return was? Example:

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

    
asked by anonymous 24.11.2017 / 17:29

2 answers

1

You need to put an if on command line . It would look like this:

if [ 'find . -type f | wc -l' -ge 1 ] ; then echo "Existe arquivos"; else echo "Nao existe arquivos"; fi
    
24.11.2017 / 17:42
0

Or browse directly for empty folders:

find . -type d -empty
    
29.11.2017 / 12:55