Showing posts with label Grep. Show all posts
Showing posts with label Grep. Show all posts

Tuesday, May 15, 2012

Find and Remove old files

This blog has been moved to http://geekaider.com

Find command usage:

find <where> <condition>
find /backup/daily -name log.*
find <where> <condition> -exec <action>
find /backup/daily -name log.* -exec ls -l {} \;
Find log files older than 2 days in /backup/daily directory
find /backup/daily/log.* -mtime +2
Find log files older than 2 days(modified 2 days back) in /backup/daily directory and remove them
find /backup/daily/log.* -mtime +2 -exec rm {} \;
NOTE: -exec <space> rm <space> {} <space> \;

Find log files older than 12 hours in /backup/daily directory and remove them
find /backup/daily/log.* -mmin +12 -exec rm {} \;
Find log files newer than 2 hours in /backup/daily directory and remove them
find /backup/daily/log.* -mmin -120 -exec rm {} \;

Grep and remove files

Grep and remove files based on serial number in name

This blog has been moved to http://geekaider.com

List the existing files

List the files in range from log.0000000670 to log.0000000675

Remove the files in range from log.0000000670 to log.0000000675

List the remaining files and cross-check if the range of files is already deleted