How to Get or Extract filename and extension in bash
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
If you found this post or this website helpful and would like to support our work, please consider making a donation. Thank you!
Help UsArticles in the same category
- Linux Bash
- Trouver rapidement et facilement l'adresse mac courante sous Linux
- How to Get or Extract filename and extension in bash
- How to check exit status of a command line in BASH ?
- Fast and easy way to get mac address on Linux
- Error "standard in must be a tty" when doing ssh username@server 'sudo command'
- Disable the usage of history using HISTSIZE,HISTFILE
- Désactiver l'historique en utilisant HISTSIZE,HISTFILE
- Comment vérifier le statut d'exécution d'une commande en BASH ?
- Comment extraire le nom et l'extension d'un fichier en Bash
- Back to previous directory in shell cd,$OLDPWD