Last active
September 17, 2021 14:46
-
-
Save cpedro/34e0ba23bc381c412c907e9cee5b7e25 to your computer and use it in GitHub Desktop.
Bash function to find all files and directories in the current director older than <days> and remove them.
This file contains hidden or 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
| # Find all files and directories in the current director older than <days> and remove them. | |
| function remove_older_than () { | |
| if [[ "$#" -eq 0 || ! "$1" =~ ^[0-9]+$ ]]; then | |
| echo "usage: remove_older_than <days>" | |
| return | |
| fi | |
| find . -ctime +${1} -type f -exec rm -f {} \; | |
| find . -ctime +${1} -type d -exec rm -rf {} \; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment