Last active
July 15, 2023 09:20
-
-
Save uriberma/f86f7c8cf9ded5e5c14dae0e760f3384 to your computer and use it in GitHub Desktop.
find files older than $days and delete them
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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