Last active
June 16, 2020 02:28
-
-
Save noogen/23945163f605e4c60a91bd506040dedc to your computer and use it in GitHub Desktop.
Cleanup Directory older than x days
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
#!/bin/sh | |
# Usage: | |
# ./cleanup-dir.sh /path/to/directory olderThanXDays(default=7) | |
EXPIRATION=${2:-7} | |
if [ ! -d "$1" ]; then | |
echo "'$1' is not a directory!" | |
echo "Usage:" | |
echo "$0 /path/to/directory" | |
exit 1 | |
fi | |
# echo $EXPIRATION | |
find "$1" -mindepth 1 -depth -type f -mtime +$EXPIRATION -exec rm -f {} \; | |
find "$1" -mindepth 1 -depth -type d -empty -delete |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment