I always forget basename

I always forget the name of this handy tool:

basename

Basename does more than return the base name of a file, i.e.,

basename /path/to/some/file.txt
file.txt

It also can give you the file without the extension, e.g.,

basename /path/to/some/file.txt .txt
file

This may seem pretty useless, but it is very handy when you are deep in some script doing something like:

for WAR in `ls *.war`; do
DIR=`basename $WAR .war`
mkdir $DIR
cd $DIR
jar -xvf $WAR
done

I just thought I’d make this entry because I always seem to forget what the name of this simple tool is…