Page 1 of 1

Remove file suffix in Bash

Posted: Wed May 16, 2012 8:34 pm
by ^rooker
A clean way for removing a file suffix (.jpg, .txt, ...) using only bash-internal syntax is as follows:

Code: Select all

FILE="bla.txt"
NAME="${FILE%.*}"
echo $NAME
This will output:
bla

Extract file suffix in Bash

Posted: Thu Jul 16, 2015 12:27 am
by peter_b
Here's the opposite of ^Rooker's snippet:
How to extract the file suffix as string in Bash?

Code: Select all

FILE="bla.txt"
NAME="${FILE##*.}"
echo $NAME
This will output:
txt