Tag Archives: file-management

./desc – quickly describe your files

Everytime I work on scientific projects, I deal with a massive amount of measurement data, lists and fragments of them etc. The problem is, that after several days or weeks, my “descriptive” filenames aren’t that descriptive anymore and I simply don’t have a clue what I did and what’s in the file. I thought it would be nice, if there was a database which holds files descriptions.

I came up with a tiny script which I placed in ~/bin (part of my $PATH) and called it “desc”. If you run it when you’re in a specific directory where you want to store description data for some files, simple type:

desc yourFileToDescribe

…and you will be promted to enter a description. The description is then stored in ./.DESCRIPTION.db and can be accessed via the “desc”-script anytime you’re in the working directory.

Here is the script, just try it out:

#!/bin/bash
# Tamas Gal - http://tamasgal.com
# desc v0.1
# this script creates a file-description-entry in ./.DESCRIPTION.db

FILE_TO_DESCRIBE=$1
FILE_DESCRIPTION=
DESCRIPTION_FILE="`pwd`/.DESCRIPTION.db"

if (( ${#FILE_TO_DESCRIBE} == "0" )) ; then
if [ -e $DESCRIPTION_FILE ] ; then
cat $DESCRIPTION_FILE
exit
fi
echo "No description(s) available."
exit
fi

if [ -e $DESCRIPTION_FILE ] ; then
if (( `grep "$FILE_TO_DESCRIBE: " $DESCRIPTION_FILE | wc -l` > "0" )) ; then
echo "`grep "$FILE_TO_DESCRIBE: " $DESCRIPTION_FILE`"
read -p "Edit (y/n)? "
[ "$REPLY" == "y" ] || exit
fi
fi

echo "Enter description for '$FILE_TO_DESCRIBE':"
read FILE_DESCRIPTION

if (( ${#FILE_DESCRIPTION} != "0" )) ; then
grep -v "$FILE_TO_DESCRIBE: " $DESCRIPTION_FILE > "$DESCRIPTION_FILE.tmp"
mv "$DESCRIPTION_FILE.tmp" $DESCRIPTION_FILE
echo "$FILE_TO_DESCRIBE: $FILE_DESCRIPTION" >> $DESCRIPTION_FILE
echo "done"
fi