HiveBrain v1.2.0
Get Started
← Back to all entries
snippetbashTip

basename — Remove leading directory portions from a path. More information: <https://www.gnu.org/software/coreu

Submitted by: @import:tldr-pages··
0
Viewed 0 times
directorycommandremovefromleadingportionsclibasename

Problem

How to use the basename command: Remove leading directory portions from a path. More information: <https://www.gnu.org/software/coreutils/manual/html_node/basename-invocation.html>.

Solution

basename — Remove leading directory portions from a path. More information: <https://www.gnu.org/software/coreutils/manual/html_node/basename-invocation.html>.

Show only the file name from a path:
basename {{path/to/file}}


Show only the rightmost directory name from a path:
basename {{path/to/directory}}


Show only the file name from a path, with a suffix removed:
basename {{path/to/file}} {{suffix}}

Code Snippets

Show only the file name from a path

basename {{path/to/file}}

Show only the rightmost directory name from a path

basename {{path/to/directory}}

Show only the file name from a path, with a suffix removed

basename {{path/to/file}} {{suffix}}

Context

tldr-pages: common/basename

Revisions (0)

No revisions yet.