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?
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.
Sign up to join this communityFirst 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.
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