a bash script to delete files older than 7 days. | ramblings of a sysadmin.

a bash script to delete files older than 7 days.

i would like to share this nifty little script, courtesy of a forum post on linuxquestions.org, one of the most authoritative websites on linux genius and learning.

#!/bin/bash
find /directoryname -type f -mtime +7 -exec rm {} \;

this script will find all the files that are older than 7 days (as indicated by mtime +7 in the /directoryname folder (note: it is advisable to use an absolute path here) and execute the rm command, which will delete (or “remove”) the files.

Leave a Reply

Post Navigation