I'm in a putty session and would like to delete files from a directory which were created in the year 2009.

Please could you give me the exact command?


3 Answers 3


First off, the fact that you are using ssh doesn't really matter. What matters is the 'shell' it has presented to you and what tools you have available. I'm going to assume you're in 'Bash' and have 'find' available.

I'm also going to assume that by 'created in year 2009' you mean 'older than 2010' as it makes it easier for me... if not then look past the break!

Try find:

find /path/to/directory/ -ctime +567 -delete

The above will delete anything more than 567 days old (roughly back to 2009 as of the date of this post)

Instead of -delete you 'could' use -print first. When you're sure its printing only what you want to delete, then use -delete.

If you don't want stuff deleted from 2008 then you 'could' do the following:

find /path/to/directory/ -ctime +567 -ctime -932 -delete

Those numbers probably aren't right though, you can fine-tune it.

Relevant sections of man find:

   -ctime n
      File's status was last changed n*24 hours ago.  See the comments
      for -atime to understand how rounding affects the interpretation
      of file status change times.

   Numeric arguments can be specified as

   +n     for greater than n,

   -n     for less than n,

   n      for exactly n.
  • 1
    You can simply combine the two date options as in 'find /path/to/files -ctime +567 -ctime -932 -delete'. The -ctime options to find and logically and-ed, while the -932 refers to a date of less than 932 days in the past. Jul 21, 2011 at 15:11
  • Bah that did occur to me but it sounded too sensible to be true so I ignored it. I will edit my answer!
    – Pricey
    Jul 21, 2011 at 15:33
  • 1
    there's an error in your edited find command: the second ctime argument should have a minus (-932) to indicate newer than 932 days instead of older. Jul 22, 2011 at 8:38
  • Bah yes very true. It was also wrong in the original >.<
    – Pricey
    Jul 22, 2011 at 8:48

I assume you are using PuTTY to connect to some computer running some distribution of Linux using SSH. Unfortunately, most Linux distributions do not record the creation date for a file. You can only find out when a file was last modified and when it was last accessed.

If you want to find all files in the current directory that were last modified in 2009, use this command:

find * \( ! -newermt '2010-01-01' \) -newermt '2008-12-31 23:59' -type f

If you want to search subdirectories too, change the * to . and remove -type f like so:

find . \( ! -newermt '2010-01-01' \) -newermt '2008-12-31 23:59'

The previous two commands will only print out the file names. If you are certain you want to delete the files, add -delete to the end:

find * \( ! -newermt '2010-01-01' \) -newermt '2008-12-31 23:59' -type f -delete

Your best bet is to write a shell script on the target server. Plink provides no processing for stdin. See: https://stackoverflow.com/questions/603187/how-to-send-commands-to-putty

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.