PawEng

Software, hardware, and the internet

Skip to: Content | Sidebar | Footer


 Subscribe to feed    

Purge Temporary Files

22 January, 2009 (7:15 pm) | Linux, Shell

Many Linux / Unix programs create temporary files with names like “#file#” or “file~”. If a program crashes, you may be left with “core” files. These files serve a purpose, but quite often it is useful to remove them. I have been using the script below for a decade or more to keep my directories clean.

#!/bin/sh
#
# Remove temporary files
#
# Usage: purge [-r]
#
if [ "$1" = "-r" ]
then
find . \( -name '#*#' -o -name '*~' -o -name '.*~' -o -name 'core' \
-o -name '*.spell' \) -print -exec rm -f {} \;
else
FILES="#*# *~ .*~ core *.spell"
/bin/rm -f $FILES
fi

Copy the code above to a file named “purge”, and give the file execute permissions:

% chmod a+x purge

Now write “purge” at the prompt to clean the current directory, and “purge -r” to clean recursively down into sub-directories.

Write a comment