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!

Deleting files of a certain age - help 1

Status
Not open for further replies.

iSeriesCodePoet

Programmer
Jan 11, 2001
1,373
US
Hello all,

Here's the thing, I am trying to do this on an AS400 QShell, which is IBM's Unix like interface to their IFS (file system). I am trying to figure out how to write the command to delete files that are older than a certain age, lets say 30 days. There is a find command, but I don't know the syntax very well, I thought someone here could help me.

Our directory structure is set up so the files are located in subdirectories such as /dirname/dir1, /dirname/dir2, etc.

This is what I have so far: find -f /dirname *.pdf This works, it displays all the files in the directories underneath /dirname. But I am trying to get the files of older that 30 days with: find -f /lawpdf *.pdf -ctime 30, but errors out on me. I am not touching the deleting until I know that this part works first.

Can anyone give me some pointers here? Mike Wills
RPG Programmer (but learning Java)

"I am bad at math because God forgot to include math.h into my program!"
 
There might be a simpler way but here is how I do it. Use touch to create a file called TIMESTAMP with a creation date newer than the files you want to delete, e.g. for Sept 2 at 00:00

touch 09020000 TIMESTAMP

Then use find to delete all files older than this file.

find /dirname -name \*.pdf \! -newer TIMESTAMP -exec rm -i {} \;

The \ characters are to protect special characters from interpretation by the shell. Judging by your examples above you may not need them. Use rm -i so you will be prompted for each deletion until you are confident the correct files are being found.

Hope this helps.

CaKiwi
 
What would be the syntax for the "-exec" to copy the files to a different directory, for testing purposes.

Is this correct? cp {} '/newdir;' /; Mike Wills
RPG Programmer (but learning Java)

"I am bad at math because God forgot to include math.h into my program!"
 
Thanks for your help. I almost have it now... Mike Wills
RPG Programmer (but learning Java)

"I am bad at math because God forgot to include math.h into my program!"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top