Javier's Blog

Mostly computers and other tech stuff,...

Tuesday, July 05, 2011

I always forget basename

I always forget the name of this handy tool:

Basename does more than return the base name of a file, i.e.,
basename /path/to/some/file.txt
It also can give you the file without the extension, e.g.,
basename /path/to/some/file.txt .txt
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

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