Skip to content

Instantly share code, notes, and snippets.

@pradeepbishnoi
Created August 3, 2017 06:32
Show Gist options
  • Select an option

  • Save pradeepbishnoi/563ce182fc697f997371b7e98d84ef2f to your computer and use it in GitHub Desktop.

Select an option

Save pradeepbishnoi/563ce182fc697f997371b7e98d84ef2f to your computer and use it in GitHub Desktop.
Clean up the folder which are older than X days from today date.
#!/bin/bash
# Clean up the folder which are older than X days from today date.
# Number value which specify how many days old
NUM_OF_DAYS=3
# Depth which the folder should be iterated
MAX_DEPTH=2
cleanup_folder() {
# Pass the folder name as argument
echo -e "Cleaning up the folder " $1
folder_path=$1
find $folder_path -maxdepth $MAX_DEPTH -type d -ctime +$NUM_OF_DAYS -exec ls -ltr {} \;
}
cleanup_folder /my/folder/path
MAX_DEPTH=1
cleanup_folder /my/other/folder/path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment