dirname
Strip the last component from a file path to get the parent directory.
Synopsis
dirname NAME
Examples
dirname /home/user/doc.txt
dirname ./scripts/run.sh
dirname /single
Common options
| Flag | Description |
|---|---|
| -z | Separate output with NUL instead of newline |
About dirname
The `dirname` command strip the last component from a file path to get the parent directory. File operation commands are essential for navigating and managing the Linux filesystem.
They form the backbone of everyday system administration and development workflows. Mastering these commands enables you to efficiently create, move, copy, and organize files and directories from the terminal, which is often faster and more scriptable than graphical alternatives.
The command accepts 1 commonly used flag shown above, though the full set of options is available in the man page (`man dirname`). The 3 examples on this page cover typical real-world usage patterns that you can copy and adapt for your own workflows.
Related commands
More File Operations Commands
Other commands in the File Operations category