Deleting files on linux – use a script to save time

Delete files script

Here’s a script for deleting files depending on location, date modified and name. Its interactive so it will ask you for the location to check in, then it will ask for the modified time e.g. delete files older then 5 days and finally it will ask for name of file as well. The name part I’ve just added to show that you can use it but I normally just use it to find files older then x number of days.

The core of the script is the simple command find and exec nohup find $LOCATION -name ‘$NAME’ -type f -mtime +$TIME -exec rm {} and we use the variable input from the read to fill out the bits we need

I’ve found this script very simple and very useful, I normally pre-load newly built servers with a script folder contain these useful scripts and your be surprised how much time it saves me.


Leave a Comment

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>