Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re^2: Deleting old files from directory

by reisinge (Friar)
on Sep 27, 2011 at 20:37 UTC ( #928178=note: print w/replies, xml ) Need Help??

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:

  • Access Time (atime) - time that the file was last accessed (e.g. read) or written to.
  • Modify Time (mtime) - time the actual contents of the file were last modified.
  • Change Time (ctime) - the time that the inode information (permissions, name, etc., i.e. the metadata) was last modified.

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://928178]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2018-01-20 13:16 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (226 votes). Check out past polls.