Skip to content

Instantly share code, notes, and snippets.

@cpedro
Last active September 17, 2021 14:46
Show Gist options
  • Select an option

  • Save cpedro/34e0ba23bc381c412c907e9cee5b7e25 to your computer and use it in GitHub Desktop.

Select an option

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.
# 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