Remove file suffix in Bash

Step-by-Step descriptions of how to do things.
Post Reply
User avatar
^rooker
Site Admin
Posts: 1483
Joined: Fri Aug 29, 2003 8:39 pm

Remove file suffix in Bash

Post 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
Jumping out of an airplane is not a basic instinct. Neither is breathing underwater. But put the two together and you're traveling through space!
User avatar
peter_b
Chatterbox
Posts: 383
Joined: Tue Nov 12, 2013 2:05 am

Extract file suffix in Bash

Post 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
Post Reply