Skip to content

Instantly share code, notes, and snippets.

@uriberma
Last active July 15, 2023 09:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uriberma/f86f7c8cf9ded5e5c14dae0e760f3384 to your computer and use it in GitHub Desktop.
Save uriberma/f86f7c8cf9ded5e5c14dae0e760f3384 to your computer and use it in GitHub Desktop.
find files older than $days and delete them
1 │ #!/bin/bash
2 │
3 │ path=$1
4 │ days=$2
5 │
6 │ # verify if path and days are set
7 │ if [ -z $path ] || [ -z $days ]; then
8 │ echo "Usage: $0 path_to_folder file_age_in_days"
9 │ exit 1
10 │ fi
11 │
12 │ # find files older than $days and delete them
13 │ find $path -type f -mtime +$days -exec rm -f {} \;
14 │
15 │ echo "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment