FreeKB - basename command in Linux
basename command in Linux

Home > Search > Linux commands

The basename command extracts the everything after the last / character in a string. In this example, just the text "Documents" will be returned.

basename /home/jeremy/Documents


basename can also be used in a shell script to print the name of the script. For example, if the script is, the following command in the script will print

echo $(basename $0)


Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter 1c237 in the box below so that we can be sure you are a human.