Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: Deleting old files from directory

by j0se (Pilgrim)
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


Comment on Re^2: Deleting old files from directory
Select or Download Code
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://928178]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2014-12-20 10:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (95 votes), past polls