This full static mirror of the Run Up to Date Linux Everywhere Project is kept online by Free Software popularizer, researcher and trainer Marco Fioretti. To know how you can support this archive, and Marco's work in general, please click here

Vacuum, the hard disk cleaner

(This is a page contributed by Eugene Wong and contains a useful script that he wrote for RULE)

There is often the need to remove certain documentation and directories that definitely aren’t needed. If one doesn’t need any games, they could be removed quite safely. Ditto for i18n or l10n, so anytime that one finds something not needed it could be added to a list of things to remove. Perhaps, one could type, "add2TheList foobar/". The script would then “>>” the directory name, every subdirectory name & file name to a list in your home directory, then "rm -rf foobar/". Later on, when one gets a chance, heinserts the floppy with the script, and runs a tool. The tool will check ~/ for the list, run diff and compare, then add the new stuff to it’s own copy.

That’s why we should call it “vacuum”, because it sucks up unwanted stuff. :^)
The first version of Vacuum (see bottom of this page) has been released on Dec 18, 2002. I intend to add long options in the new year. For the moment, Vacuum accepts these short options:

  • -e = empty this item from the spool directory
  • -g = display equivalent working directory (see below)
  • -r = restore
  • -s = suck up

For -e you would have to specify what you would like to delete. To clean out the entire spool directory, you’d have to type, “vacuum -e /var/spool/vacuum/*”. The * is important. In future versions, this should record what was emptied, for future sucking up, but for now, it doesn’t do anything.

I felt that it would be important to have -g because it makes it easier to cd back and forth between the equivalent directories. This is important when you don’t want to delete all of the subdirectories. You could suck up all of them, then restore some. You could also use it to look around. For example, let’s pretend that you just sucked up /usr/XFree86/lib/X11/locale. To check the spool directory, You’d type:

  root# cd `vacuum -g`
  root# pwd
  /var/spool/vacuum/usr/XFree86/lib/X11/locale
  root# cd `vacuum -g`
  root# pwd
  /usr/XFree86/lib/X11/locale
  root# cd ..; pwd
  /usr/XFree86/lib/X11
  root# cd `vacuum -g`
  root# pwd
  /var/spool/vacuum/usr/XFree86/lib/X11/locale
  root#

Originally, I intended to have -g actually go to the equivalent directory “outside” of the script, but I don’t know how to do that. If you have suggestions, then please let me know.

Notes

  • -r is just as we decided. Just like -e, you have to specify what you want to restore.
  • -s is also just as we decided. Just like -e, you have to specify what you want to restore.

It should be noted that I don’t use “cp -dpR –parent” & “rm -rf” as much as I may have mentioned. Instead I use “mkdir -p” & “mv”. If you have suggestions, then please let me know.

#!/bin/bash
# vim:sw=4 ts=4

# Marco suggested using the modeline script by ESR. I don't have that handy
# right now, but it should be findable through google. For the time being,
# I am going to try to use the code from /usr/bin/modeline2fb  Unfortunately it
# uses Perl, which may not work with Bash scripts

# ls -ltru should help us find the time of last access, as opposed to
# ls -ltr, which should give us the time of last modification. This should be
# good for finding useless files.

####### Variables #######
config_dir=/etc/
list_dir=/var/db/vacuum/
spool_dir=/var/spool/vacuum/
test_dir=/tmp/vacuumtest/
#working_spool_dir=

config_file=vacuum.cfg
list_file=vacuum.lst

NO_ARGS=0
E_OPTERROR=65
YES=1
NO=0
IS_S=$NO		# has the -S option been given? "no" is default.
IS_a=$NO		# has the -a option been given? "no" is default.
IS_e=$NO		# has the -e option been given? "no" is default.
IS_g=$NO		# has the -g option been given? "no" is default.
IS_r=$NO		# has the -r option been given? "no" is default.
IS_s=$NO		# has the -s option been given? "no" is default.

#d="Debug Message: "
####### End Section #######

#echo ${d}STARTING TO ECHO VARIABLES...
#echo ${d}spool_dir   = ${spool_dir}
#echo ${d}list_dir    = ${list_dir}
#echo ${d}config_dir  = ${config_dir}
#echo ${d}test_dir    = ${test_dir}
#echo
#echo ${d}config_file = ${config_file}
#echo ${d}list_file   = ${list_file}
#echo ${d}FINISHED ECHOING VARIABLES.
#echo
#echo
#echo ${d}"STARTING TO TEST VARIABLES..."
#ls ${spool_dir}
#ls ${list_dir}
#ls ${config_dir}
#ls ${test_dir}
#echo
#ls ${config_dir}${config_file}
#ls ${list_dir}${list_file}
#echo ${d}FINISHED TESTING VARIABLES.
#echo
#echo

if [ $# -eq "$NO_ARGS" ]
then
	echo "Usage: `basename $0` options (-a | -e | -r | -s)"
	exit $E_OPTERROR
fi

# For more information on how to use getopts [notice the "s" at the end
# of the word] & why we shouldn't use getopt [notice the lack of an
# "s" @ the end of the word], consult the Advanced Bash Scripting Guide.
# The information will be difficult to find. Go to chapter 17 and find getopts.
# On the RULE mailing list, it was suggested that we consult ESR's modelines
# script on how to use getopt(s). I checked a Gentoo version, & it didn't seem
# to help because it was a perl script, and it didn't seem to use getopt.
while getopts ":aegrs" Option
# a, e, r, & s are the options [flags] expected
do
	case $Option in
		a ) IS_a=$YES
			;;
		e ) IS_e=$YES
			;;
		g ) IS_g=$YES
			;;
		r ) IS_r=$YES
			;;
		s ) IS_s=$YES
			;;
		* ) echo "unimplimented option chosen"
			;;
	esac
done
shift $((OPTIND - 1))
# Move arguement pointer to next.

# if there is -e or --empty
# be sure to confirm that they definitely want to empty.
# we should require that they specify -a or --all so that users are used to
# doing it while it is still early. This way, we can add other options in the
# future. Possible other options include a number to represent how many days
# ago, should be deleted. IE: vacuum -e4 represents "empty the bag of files
# that were sucked up 4 days ago or later. leave all files that were vacuumed
# earlier than 4 days.". Perhaps we should allow for the same options as -a
if [ $IS_e -eq $YES ]
then
	echo "executing \"rm -rf ${spool_dir}*\" to empty spool directory"
	rm -rf ${spool_dir}*
	echo "done"
fi

if [ $IS_g -eq $YES ]
then
	if [ "`pwd|cut -d'/' -f2-4`" = "var/spool/vacuum" ]
	then
		echo "/`pwd|cut -d'/' -f5-`"
	else
		echo "${spool_dir}`pwd|cut -d'/' -f2-`"
	fi
fi

# if there is -r or --restore
# move back everything without question if there are no other arguements
# move back only what is specified in the other arguments, including any
# subdirectories
# perhaps we should allow for the same options of -e
# The following needs to edited to remove the ${spool_dir} part of the directoryname
if [ $IS_r -eq $YES ]
then
	for arg in "$@";
	do
		# Instead of just using the mv command, we use cp. cp allows
		# us to preserve the directory structure. mv doesn't.
		# See man cp & man mv for more details. I am using GNU options.
		#
		# Also, what do we do with the -u & -x options of cp?
		#cp -dpR --parents `pwd|cut -d"/" -f5-`/ ${test_dir}
		mkdir -p /`pwd|cut -d"/" -f5-`
		mv -f ${arg} /`pwd|cut -d"/" -f5-`
		if [ $? ]
		then
			rm -rf ${arg}
		fi
	#cp -dpR --parents `pwd|cut -d'/' -f5-`/${arg} ${test_dir}
#		rm -rf ${arg}
	done
	#cp -dpR --parents ${@} ${test_dir}`pwd|cut -d'/' -f5-`/
	#cp -dpR --parents ${@} /
	#rm -rf ${@}
fi

if [ $IS_s -eq $YES ]
then
	echo you gave -s as an arguement
	for arg in "$@";
	do
		# Instead of just using the mv command, we use cp. cp allows
		# us to preserve the directory structure. mv doesn't.
		# See man cp & man mv for more details. I am using GNU options.
		#
		# Also, what do we do with the -u & -x options of cp?
		#cp -dpR --parents `pwd` ${spool_dir}
		mkdir -p ${spool_dir}`pwd|cut -d"/" -f2-`
		mv -f ${arg} ${spool_dir}`pwd|cut -d"/" -f2-`
		if [ $? ]
		then
			rm -rf ${arg}
		fi
		#cp -dpR --parents ${arg} ${spool_dir}
	done
fi

exit
RULE = Run Up to Date Linux Everywhere
This entry was posted in Software. Bookmark the permalink.