1.11M Members

Filtering and removing older files



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?


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.

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