Purpose: interactively clear out a directory.
Usage: empty_shortterm
For each file in the current directory, displays the file and some metadata. The user is prompted to either assign a new place for the file or delete it. Files "deleted" in this procedure may be reviewed in ./rubbish/
Changelog:
2022-359 initial development
2023-247 reformat/redocument a tad
Source code (perhaps slightly corrupted) is as follows.
filesize() {
RAWSIZE=`stat -c '%s' "$1"`
if [ "$RAWSIZE" -gt 4194304 ]
then
echo "$((RAWSIZE / 1048576)) MiB"
elif [ "$RAWSIZE" -gt 4096 ]
then
echo "$((RAWSIZE / 1024)) KiB"
else
echo "${RAWSIZE} bytes"
fi
}
mkdir rubbish
for FNAME in *
do
if [ -f "$FNAME" ]
then
FTYPE=`file --mime-type "$FNAME"`
FSIZE=`filesize "$FNAME"`
FDATE=`stat -c '%z' "$FNAME" | cut -d ' ' -f 1`
echo -n "${FTYPE}, ${FSIZE}, from ${FDATE}. Display? "
read DC
if [ "${DC#y}" != "$DC" ]
then
xdg-open "$FNAME" $source
fi
echo -n "Enter new path, or leave blank to delete: "
read NP
if [ -n "$NP" ]
then
echo "Moving ${FNAME} to ${NP}"
mv "$FNAME" "$NP"
else
echo "Marking ${FNAME} for deletion"
mv "$FNAME" 'rubbish'
fi
else
echo "Skipping ${FNAME} (not regular file)"
fi
done
echo -n "Delete everything marked for deletion? "
read DC
if [ "${DC#y}" != "$DC" ]
then
rm -r rubbish
else
echo "Review rubbish/ for important items and delete what remains"
fi