Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I thought of using watch command to delete files in a directory every N seconds with the command running in background.

This is what I was planning to use:

nohup watch -n1200 rm -rf /var/log/radius/radacct/* &

It works, but when I see the running process, it shows me the following output -

[root@Free-Radius]# ps -aef | grep watch
root     27326 10649  0 15:23 pts/0    00:00:00 watch -n1200 rm -rf /var/log/radius/radacct/
root     27404 10649  0 15:24 pts/0    00:00:00 grep watch

Now there will be a new file detail-20130817 tomorrow, which will not get deleted. Is there a way to achieve it using watch command. I know its easily doable using a simple bash script or cron job, but just wanted to know if it can be done using watch.

share|improve this question
use rather .../detail-$(date +%Y%m%d) – val0x00ff Aug 16 '13 at 10:27
Or configure the application to not write any logs, if you're just going to delete them anyway. – Michael Kjörling Aug 16 '13 at 10:45
You should use watch 'rm -rf something*' to avoid the expansion of * by the shell before the execution of watch. – enzotib Aug 16 '13 at 10:52
Thank you @val0x00ff. The suggestion worked – Shrijit Aug 18 '13 at 18:50
Thank you @enzotib. Your suggestion too worked :) – Shrijit Aug 18 '13 at 18:50
up vote 2 down vote accepted

If using the watch command from procps (which starts a shell to interpret the command line that's made out of the concatenation of its arguments), use:

nohup watch -n1200 'rm -rf /var/log/radius/radacct/*' &

With some other implementations, you may have to call the shell manually:

nohup watch -n1200 sh -c 'rm -rf /var/log/radius/radacct/*' &

Why not use cron though?

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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