Question : How to delete files and folders having more than 5 days of age using Linux BASH ?

Hi,

I would like to request an assistant.

May i know how to delete files and folders having more than 15 days of age using BASH ?

FYI, the folders and files that i would like to delete is located inside /backup folder.

Appreciates of any assistant.

Thank you.

Answer : How to delete files and folders having more than 5 days of age using Linux BASH ?

You can use the "find" command.

The "find" command finds files based on many different criteria specified on the command line.

This example will only find and print the full path of files older than 15 days on the entire filesystem:

find /* -mtime +15 -print

You can also cd to another directory and find will search starting from that directory

cd /another/directory
find . -mtime +15 -print

also this will do the same:

find /another/directory/* -mtime +15 -print

The find command can also execte another command on each file found, for exmple

find /another/directory/* -mtime +15 -exec rm {} \;

Will delete all matching files.

BE VERY CAREFULL WHEN TESTING THE -exec ARGUMENT SPECIALLY WHEN USING "rm"

Random Solutions  
 
programming4us programming4us