basename
Quick Reference
Command Name:
basename
Category:
file management
Platform:
linux
Basic Usage:
Common Use Cases
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:
# Extract filename from a path basename /usr/local/bin/example.txt # Output: example.txt
Advanced Examples:
# Use in a shell script to process filenames for file in /var/log/*.log; do name=$(basename "$file") echo "Processing $name" done