Why does

$ while true ; do 'date; time find /tmp/test -type f \
  -exec cp /dev/null {} \;';sleep 3600; done

not work and instead return an error message:

-bash: date; time find /tmp/test -type f -exec cp /dev/null {} \;: No such file or directory

I have tried escaping ; and {} but I still get the same error. And yes, there is a /tmp/test directory.

  • 2
    why you put it in the single quote? – Hossein Vatani Jul 29 '18 at 6:01
  • 1
    The error in the title is wrong. Should really be -bash: ...: No such file or directory. find never executes, so it can't give an error. – Kusalananda Jul 29 '18 at 7:17

Remove the quotes and it will work as expected (and yes, you must have two semi colons in a row).


The argument to do is a single command; further commands use a command chain.

while true ; do date ; find ... ; sleep 3600 ; done
while true; do
    time find /tmp/test -type f -exec cp /dev/null {} \;
    sleep 3600

The single quotes in your command makes the shell interpret the quoted string as the name of a command to execute, and it can't find it, which is why you get that specific error.

Another way of doing the emptying of files under /tmp/test every hour is via a cronjob with the following schedule:

0 * * * * find /tmp/test -type f -exec cp /dev/null {} \;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.