Skip to content

Instantly share code, notes, and snippets.

@abackstrom
Created April 17, 2012 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abackstrom/2406388 to your computer and use it in GitHub Desktop.
Save abackstrom/2406388 to your computer and use it in GitHub Desktop.
mounted-tmp.conf from Ubuntu
#!/bin/bash
#
# modified for use as a callable script
#
# USAGE
#
# cleanup.sh [path] [days]
#
# path is required. days defaults to 14.
#
MOUNTPOINT=$1
TMPTIME=${2:-14}
if [ x$MOUNTPOINT = x ] ; then
exit 1
fi
cd "${MOUNTPOINT}" || exit 1
case "${TMPTIME}" in
-*|infinite|infinity)
exit 0
;;
esac
if [ "${TMPTIME}" = "0" -o -z "${TMPTIME}" ]
then
TEXPR=""
DEXPR=""
else
TEXPR="-mtime +${TMPTIME} -ctime +${TMPTIME} -atime +${TMPTIME}"
DEXPR="-mtime +${TMPTIME} -ctime +${TMPTIME}"
fi
EXCEPT='! -name .
! ( -path ./lost+found -uid 0 )
! ( -path ./quota.user -uid 0 )
! ( -path ./aquota.user -uid 0 )
! ( -path ./quota.group -uid 0 )
! ( -path ./aquota.group -uid 0 )
! ( -path ./.journal -uid 0 )
! ( -path ./.clean -uid 0 )
! ( -path "./...security*" -uid 0 )'
# Remove all old files, then all empty directories
find . -depth -xdev $TEXPR $EXCEPT ! -type d -delete
find . -depth -xdev $DEXPR $EXCEPT -type d -empty -delete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment