Linux command
basename 命令
文件
复制后可按需替换文件名、目录或参数。
常用示例
Extract
basename [/path/to/file.txt]
Remove
basename [/path/to/file.txt] [.txt]
Multiple
basename -a [/path/to/file1.txt] [/path/to/file2.txt]
Example
basename -s [.txt] [/path/to/file.txt]
说明
basename removes directory components from a pathname, leaving only the final filename. It can optionally remove a trailing suffix, making it useful for extracting filenames in shell scripts. The tool is part of GNU coreutils and commonly used in build scripts and file processing pipelines.
参数
- -a, --multiple
- Process multiple arguments
- -s, --suffix=_suffix_
- Remove trailing suffix
- -z, --zero
- Separate output with NUL instead of newline
FAQ
What is the basename command used for?
basename removes directory components from a pathname, leaving only the final filename. It can optionally remove a trailing suffix, making it useful for extracting filenames in shell scripts. The tool is part of GNU coreutils and commonly used in build scripts and file processing pipelines.
How do I run a basic basename example?
Run `basename [/path/to/file.txt]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -a, --multiple do in basename?
Process multiple arguments