Skip to content

Instantly share code, notes, and snippets.

@mguymon
Created March 13, 2012 14:52
Show Gist options
  • Save mguymon/2029254 to your computer and use it in GitHub Desktop.
Save mguymon/2029254 to your computer and use it in GitHub Desktop.
Remove old directories
DAYS = 30
DIR_COUNT=`ls -tr | wc -l`
if [ "${DIR_COUNT}" -gt ${DAYS} ]
then
ls | sort -n | head -`expr ${DIR_COUNT} - ${DAYS}` | xargs echo "removing dirs
: "
ls | sort -n | head -`expr ${DIR_COUNT} - ${DAYS}` | xargs rm -rf
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment