The basename command

Many times it is useful to extract the filename out of a pathname. For example, is the pathname is /usr/local/bin/cdisks, then we want to strip off all directories and forward slashes and come up with cdisks, which is the actual file name. The command basename does that for us nicely.

[alice@onyx guide]: basename /usr/local/bin/cdisks
cdisks
[alice@onyx guide]:

The basename command can also be used to remove the extension of a file. For example:

[alice@onyx guide]: basename xyz.txt .txt
xyz
[alice@onyx guide]: