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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to remove files from 2001 to 2002 3

Status
Not open for further replies.

copperslim

Technical User
Dec 13, 2002
101
GB
My filesystem is filling up.
How do I write a script that will remove all the files from 2001 to 2002.

I do not want to type rm $filename one at a time.
Thanx
 
A somewhat indirect answer is to use touch and find

Code:
touch -t 200101010000 oldest
touch -t 200212312359 newest
These set a pair of files which are at the limits of the required date range

Code:
find . \( -newer oldest -a \! -newer newest \)
This finds all the files between those two dates

Once you're happy with the command, you can make it delete the files with
Code:
find . \( -newer oldest -a \! -newer newest \) -exec rm {} \;

--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top