Math-Linux.com

Knowledge base dedicated to Linux and applied mathematics.

Home > Linux > Bash > How to Get or Extract filename and extension in bash

How to Get or Extract filename and extension in bash

All the versions of this article: [English] [français]

nsoualem@gold: -> PICTURE=Tux.jpg
nsoualem@gold: -> echo ${PICTURE%%.*}
Tux
nsoualem@gold: -> echo ${PICTURE#*.}
jpg

For multiples extensions files:

nsoualem@gold: -> FILE=archive.tar.gz
nsoualem@gold: -> echo ${FILE%%.*}
archive
nsoualem@gold: -> echo ${FILE%.*}
archive.tar
nsoualem@gold: -> echo ${FILE#*.}
tar.gz
nsoualem@gold: -> echo ${FILE##*.}
gz

Any message or comments?

comments powered by Disqus