Remove files older than X

Discussion in 'Command Line' started by Rob, Oct 28, 2011.

  1. Rob

    Rob Administrator Staff Member

    Joined:
    Oct 27, 2011
    Messages:
    606
    Likes Received:
    271
    We have video cameras saving footage on to a fileserver - but it's taking up about 30G/day.. so I wanted to do something to remove files older than a week or so.. All it took was throwing this command into a cron job:



    Code:
    /usr/bin/find /mnt/data/cam/201?/ -type f -mtime +8 -exec rm -f {} \;
    

    This will find files under the /mnt/data/cam/2011/ (or 2012, 2013, etc..) directory that are 8 days old and remove them. You can test the command by replacing "rm -f" with "ls" to see what files it found..
     
  2. gcawood

    gcawood Administrator Staff Member

    Joined:
    Oct 28, 2011
    Messages:
    49
    Likes Received:
    19
    If you just want to find a list of files that is older than 90 days. I find that this command works pretty well.

    Code:
    find . -name "*" -mtime -90 -print 
     
    Rob likes this.
  3. bashcommando

    bashcommando Active Member

    Joined:
    Jan 28, 2014
    Messages:
    223
    Likes Received:
    49
    There goes X10
     

Share This Page