LDP/LDP/guide/docbook/abs-guide/wipedir.sh

39 lines
921 B
Bash

#!/bin/bash
E_WRONG_DIRECTORY=83
clear # Clear screen.
TargetDirectory=/home/bozo/projects/GreatAmericanNovel
cd $TargetDirectory
echo "Deleting stale files in $TargetDirectory."
if [ "$PWD" != "$TargetDirectory" ]
then # Keep from wiping out wrong directory by accident.
echo "Wrong directory!"
echo "In $PWD, rather than $TargetDirectory!"
echo "Bailing out!"
exit $E_WRONG_DIRECTORY
fi
rm -rf *
rm .[A-Za-z0-9]* # Delete dotfiles.
# rm -f .[^.]* ..?* to remove filenames beginning with multiple dots.
# (shopt -s dotglob; rm -f *) will also work.
# Thanks, S.C. for pointing this out.
# A filename (`basename`) may contain all characters in the 0 - 255 range,
#+ except "/".
# Deleting files beginning with weird characters, such as -
#+ is left as an exercise.
echo
echo "Done."
echo "Old files deleted in $TargetDirectory."
echo
# Various other operations here, as necessary.
exit $?