Remove files older than X

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

  1. Rob

    Rob Administrator Staff Member

    Messages:
    573
    Likes Received:
    184
    Trophy Points:
    43
    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

    Messages:
    49
    Likes Received:
    15
    Trophy Points:
    0
    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

    Messages:
    135
    Likes Received:
    32
    Trophy Points:
    28
    There goes X10

Share This Page