Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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 have a folder which contains many files. I want to delete files older than 30 days, so I use the command:

find cache/ -mtime +30 -exec rm {} \;

But my SSH session disconnects before the command completes.

How can I limit the number of files that are deleted at one time? For example:

find cache/ -mtime +30 -LIMIT 10000 -exec rm {} \;
share|improve this question
What do you mean by "timeout"? – David Schwartz Jan 15 '12 at 4:15
wait a longtime and putty show disconnect – dinh Jan 15 '12 at 4:29

Run it in a screen session. That way when putty disconnects the job is still running on the server. Just reconnect and use screen -r to re-attach the screen session to see the progress.

share|improve this answer
how to run in screen session? – dinh Jan 15 '12 at 9:22
just run the screen command and it will create a new screen session for you. It's probably best to skim through the man page for screen, but I guarantee you it will quickly become one of your most used tools. Good luck! – d34dh0r53 Jan 15 '12 at 10:45

You could also run the command with nohup, like this:

nohup find cache/ -mtime +30 -exec rm {} \; &

Then cat nohup.out to keep an eye on the ouput.

share|improve this answer

You could do something like:

find cache/ -mtime +30 | head -n 10000 | xargs rm

This would work if the filenames were fairly "vanilla" (no spaces, special characters, etc) and short.

But if you'd rather just wait for your original command to complete, you can just tell PuTTY to send SSH keepalive messages every so often; see the PuTTY docs for the details. I usually use a value between 45–60 seconds, myself.

share|improve this answer
find cache/ -mtime +30 -print0 | xargs -0 rm -v

Then it'll output every file that is deleted, that should prevent your session from timing out .

Or, put this in cron, as it's something that sounds like it should be automated.

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.