basename
Quick Reference
Command Name:
basename
Category:
file management
Platform:
linux
Basic Usage:
Common Use Cases
- 1
File path processing
Extract the filename from a full path
- 2
Script automation
Process file paths in automated scripts
- 3
File management
Work with filenames without directory components
- 4
Path manipulation
Extract and manipulate file path components
Syntax
basename NAME [SUFFIX] basename OPTION... NAME...
Options
| Option | Description |
|---|---|
| -a, --multiple | Support multiple arguments and treat each as a NAME (GNU version) |
| -s, --suffix=SUFFIX | Remove a trailing SUFFIX; implies -a (GNU version) |
| -z, --zero | End each output line with NUL, not newline (GNU version) |
| --help | Display help information and exit |
| --version | Output version information and exit |
Examples
How to Use These Examples
The examples below show common ways to use the basename command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.
Basic Examples:
basename /usr/local/bin/example.txt
basename example.txt .txt
basename /usr/local/bin/
basename -a /path/file1.txt /path/file2.txt