UnixServerAdmin

Server Administration & Management

How to delete files in directory by date

Sometimes, We need to delete files in a directory by date. This command will search and delete files that are 180 days old. This can be adjusted to what ever.  You can alter the number of days to find and delete.

# find /var/www/html/ -type f -ctime +180 -exec rm -f {} ; -print

Sometimes, rm command take long time and increase server load,

So please use -delete option, it is a bit faster (only works with GNU find version 4.2.XX or higher)

# find –version
GNU find version 4.2.XX or higher

How to remove txt file under /var/www/html/ directory, more than 30 days old.

# find /var/www/html/ -type f -ctime +30 -name “*.txt” -delete

How to remove txt file under /var/www/html/ directory

# find /var/www/html/ -type f  -name “*.txt” -delete

How to find txt file under /var/www/html directory

# find /var/www/html/ -type f  -name “*.txt”

 

 

February 12, 2012 Posted by | Tips & Tricks, Unix/Linux | , , , | Leave a comment