1,105,254 Community Members

Filtering and removing older files

ashwil
Newbie Poster
1 post since Sep 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
Unverified Member
 
0
 

Hi,

I need to filter and remove files which are older than a month from a Unix folder. I got the below command from Daniweb.

find /path/to/directory -type f -mtime +31 -exec ls -ltr {} \; Can I use this command in ksh script?

Does the file name need to be in a special format for this command to work? How does this command work? Does it a recognise the creation time of the file automatically even if it is not mentioned in the file name?

Member Avatar
masijade
Industrious Poster
4,165 posts since Feb 2006
Reputation Points: 1,351 [?]
Q&As Helped to Solve: 510 [?]
Skill Endorsements: 22 [?]
Team Colleague
Featured
 
0
 

That "mtime" is modification time, read from the file meta data, it does not need to be in the name, at all. If you want to remove the files you need to change the ls command to an rm command, of course. run "man find". You might also want to look into the xargs command.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: