http://www.perlmonks.org?node_id=928178


in reply to Re: Deleting old files from directory
in thread Deleting old files from directory

To handle spaces in filenames:
find <directory> -type f -mtime +10 -name "*some*pattern*.txt" -exec r +m -f '{}' \;
On first run(s), you should consider using ls -l instead of rm -f.

I see you've used -ctime; here are the differences among Unix timestamps:

Update: atime info corrected; for more see man 2 stat.

Have a nice day, j

Replies are listed 'Best First'.
Re^3: Deleting old files from directory
by chrestomanci (Priest) on Sep 28, 2011 at 08:57 UTC

    I use an explicit pipe to xargs instead of using the built in delete action, because that way it is easier to check I am deleting the correct files, as I can use ls on the end of the xargs command instead of rm.

    Another way to handle spaces in filenames is to configure find to separate output with nulls instead of spaces, and then have xargs expect those nulls.

    find <directory> <conditions> -print0 | xargs -0 ls -l