basename's Examples

basename command strips directory information and suffixes from file names

$ basename file

it strips directory and its suffix from filenames

basename file.txt .txt

it removes suffix of multiple files

$ basename file1.txt file2.txt .txt

it removes suffix of multiple files

$ basename file1.txt file2.txt .txt

if we give full path of the file th basename command gives the filename as the output

$ basename /user/include/string.h

if we give full path of the file th basename command gives the filename as the output

$ basename /user/include/string.h

it removes the suffix .h and prints the output

$ basename user/include/string.h .h

-a is used to handle multiple inputs

$ basename -a /user/expert/home/ home/expert/unicode/ /user/ include/studio.h

-a is used to handle multiple inputs

$ basename -a /user/expert/home/ home/expert/unicode/ /user/ include/studio.h

.txt is removed from all the files when basename command followed by -s is used

$ basename -s .txt pavani.txt

-z  to get a zero byte at the end of each line than a new line.

$ basename -z -s file1.txt

removes all suffixes

$ basename -a string.h linux .h .h

DevOpsSchool
Typically replies within an hour

DevOpsSchool
Hi there 👋

How can I help you?
×
Chat with Us