Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RM files by date range. 1

Status
Not open for further replies.

tnodine

IS-IT--Management
Dec 12, 2001
21
US
can someone please let me know a command in unix to remove/delete files in specific date range?

for instance, I want to delete all files in a directory with the year of 2003. or maybe all files for 2004 between Jan and May?

thanks for the help.

T.
 
Code:
touch -d'2004-01-01 00:00:00' 2004-Jan
touch -d'2004-05-31 23:59:59' 2004-May
find /some/dir -newer 2004-Jan -not -newer 2004-May -exec ls -la {} \;
instead ls -la use rm, but performing a test before isn't a bad idea.

seeking a job as java-programmer in Berlin:
 
Hi,

You can also use find with -mtime switch ( modified time )

to list the files not modified since 365 days
Code:
find /somewhere -mtime +365 -exec ls -al {} \;

to remove this listed files, replace "exec ls -l" by "exec rm"
 
aau
tnodine requires a range of dates. I believe you could use
Code:
find /some/dir -mtime +365 -mtime -700
but stefanwagner's suggestion is far more user friendly. Can you tell me the relevant number of days to put for Jan -> May 2004?

Columb Healy
 

Basically, what I want to do is remove all the files that return as result of :

ls -la | grep "2003 "


This will give me all files in 2003.

Thanks,
T.
 
Nevermind my last post.. I beleive I was able to take care of it using aau's suggestion.

Thanks for everyones help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top