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?

4 Years
Discussion Span
Last Post by masijade

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 topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.