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

Korn Shell Q or 2 1

Status
Not open for further replies.

Funkymatt

Programmer
Aug 27, 2002
101
US
Never really used Korn (not very efficient in UNIX either) so this has been painful.

In my current working directory there are files with the following general naming conventions:

SF_AD_MMDDYYnn.DEL
SF_AD_MMDDYYnn.EXP
Ad_sf_MMDDYYnnnnn.DAT
where n represents the number of that particular file sent over on that day.

I would like to write a simple script (I can use AutoSys to kick off the script every day) that will delete all files in that directory that are older than one week. There are other files in the directory that I do not want to touch.

I was thinking, first check the first file in the directory if it is like *MMDDYY*.DEL or *MMDDYY*.EXP or *MMDDYY*.DAT then check the date using some date comparison in an if block. If it is older than one week, delete it, else leave it.

Very overwhelming and the Korn Shell book by Olczak ins't helping me much.

Thanks,
Matt
 
Is it essential to look at the file name? It is very easy when looking at the file creation date or modification time (ls -l will reveal) and delete according to that.

e.g.

find <start_path> -type f -mtime +7 -exec rm -f {} \;
IBM Certified Confused - MQSeries
IBM Certified Flabbergasted - AIX 5 pSeries System Administration
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top