Terminal Scripts - Bytesized Hosting Wiki

Just a collection of useful scripts

To check a folder and delete all files not accessed in X days

{PATH} = your path to the folder you want to monitor.

{TIME} = time in days since last access

#!/bin/bash

find {PATH} -mindepth 1 -atime +{TIME} -delete

This will find all files and folders within {PATH}, and delete all files and folders not accessed within {TIME} days.

To do a trial run (recommended!) just remove the -delete from the end. If you'd like to keep one more depth of folders change mindepth to 2.


Last Author Contributors Versions Last update
davidc75 None 6 Fri, 12 Mar 2021 05:39:21 +0100