UNIX cmd -find empty files in folder else sleep for 8hrs

Hello,

I am trying to write a unix cmd , that if files in folder /path/FTP are all zero kb or empty then good to go, if not empty then sleep for 8 hrs.

Following cmd list me the files which are not empty, But when I am incorporating IF ELSE cmd fails

find /path/FTP. -type f -exec wc -l {} \; | awk '$1 >0 {print $2}'

Any help will be appreciated.
Thanks

Please use code tags as required by forum rules!

I'm a bit unsure - how do you want to incorporate IF ELSE in a find command? Did you consider the -size test? You can have two (or more) branches in the find parameters. Read man find .

And, why and how do you differentiate between zero kB and empty?

Please be way more precise with your specification.

Find itself can test for non-empty files, in an if test this could look like:

if [ -n "`find /path/FTP. -type f -size +0`" ]; then sleep 28800; fi
1 Like

Also, you can stop at the first file; use 'read' or 'line' to detect the first line. Be careful of read, as "| read x' in ksh is fine, but in bash, read runs in an implicit subshell and x is not set for your shell, so try explicit subshell in which you test x: '|( read x ; . . . .)'. While 'line' is not a built-in (if you have it at all), it is good at expediting data out of a pipe, where one byte reads are given special treatment, do not block awaiting a bull buffer, and it returns 1 to $? on EOF.

1 Like

Maybe wait and repeat?

until find /path/FTP. -type f -size 0 | awk '{print; exit 1}'
do
  sleep 28800
done

Instead of until or while you can also use an if clause. It gets the exit status of the awk command, 0 normally, 1 if a zero-file was found.
NB in the shell an exit status 0 is a true condition (for practical reasons).
You can suppress awk's output with >/dev/null , this doesn't affect its exit status.

---------- Post updated at 02:57 PM ---------- Previous update was at 02:49 PM ----------

Just seeing the proposal with line .

while find /path/FTP. -type f -size 0 | line
do
 sleep 28800
done

Thank You everyone, My problem is solved , If cmd worked for me.

I think in find the size must be '+0' for > 0, else you find empty files.