dirname - strip last component from file name
| Use Case | Command | Description |
|---|---|---|
| π Get directory from path | dirname /path/to/file | Outputs the directory portion of the path |
| π Strip trailing slash | dirname /path/to/dir/ | Removes trailing slash and last component |
| π File with no slash | dirname filename | Outputs "." (current directory) |
| π¦ Multiple names | dirname dir1/str dir2/str | Processes multiple arguments, outputting each directory |
| π Zeroβseparated output | dirname -z file1 file2 | Outputs NULβterminated strings for scripting |
dirname [OPTION] NAME...
Output each NAME with its last nonβslash component and trailing slashes removed; if NAME contains no /'s, output '.' (meaning the current directory).
π end each output line with NUL, not newline
β display this help and exit
π output version information and exit
dirname /usr/bin/
-> "/usr"
π Strips the last component, leaving the directory path.
dirname dir1/str dir2/str
-> "dir1" followed by "dir2"
π Processes multiple names, outputting each directory part.
dirname stdio.h
-> "."
βͺ No slashes, so outputs the current directory symbol.
Written by David MacKenzie and Jim Meyering.
GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
Report any translation bugs to <https://translationproject.org/team/>
Copyright Β© 2020 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
basename(1), readlink(1)
Full documentation <https://www.gnu.org/software/coreutils/dirname>
or available locally via: info '(coreutils) dirname invocation'
Generated by phpman v4.9.25-25-g40dbf62 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-16 13:50 @2600:1f28:365:80b0:8802:8bb4:3873:328e
CrawledBy CCBot/2.0 (https://commoncrawl.org/faq/)
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format