Introduction
The Linux command basename is a utility that is used to strip directory and suffix from filenames. It is a very useful command for extracting the filename from a given pathname. It can also be used to extract the suffix from a filename. This command is available in most Linux distributions and is a part of the GNU Core Utilities package. It is a very useful tool for manipulating filenames and can be used in a variety of ways.
Examples
The basename Linux command is used to strip directory and suffix from filenames. It returns the filename without any leading directory components.
Syntax:
basename [OPTION]… NAME [SUFFIX]
Example:
$ basename /usr/local/bin/bash
bash
Linux Command: Basename
The basename command is a Linux utility used to strip directory and suffix from filenames. It is used to extract the filename from a given pathname. It is a standard Unix program and is included in most Linux distributions.
The syntax for the basename command is as follows:
basename [OPTION]... [NAME]...
The options for the basename command are as follows:
- -a, –multiple : Treat each NAME as a separate argument, even if it contains spaces.
- -s, –suffix : Remove a trailing SUFFIX; implies -a.
- -z, –zero : End each output line with NUL, not newline.
The basename command is useful for extracting the filename from a given pathname. For example, if you have a file located at /home/user/myfile.txt
, you can use the basename command to extract the filename myfile.txt
from the pathname.
The basename command is a useful tool for scripting and automation tasks. It can be used to extract filenames from a list of pathnames, or to strip off a suffix from a filename.