Skip to content

dirname and basename

dirname : Directory Name

This command will print the path of the directory in which file exists

dirname filename

basename :

This command will print the filename that will not include the path

basename file-path

To print the file extension only

filename='filename.txt'

Then run

echo "${filename#*.}"

To print the file name without extension

filename='filename.txt'
echo "${filename%*.}"