Skip to content

Instantly share code, notes, and snippets.

@noogen
Last active June 16, 2020 02:28
Show Gist options
  • Save noogen/23945163f605e4c60a91bd506040dedc to your computer and use it in GitHub Desktop.
Save noogen/23945163f605e4c60a91bd506040dedc to your computer and use it in GitHub Desktop.
Cleanup Directory older than x days
#!/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