dirname
noun
say it: “DUR-naym” /ˈdɝneɪm/
A command that cuts the last part off a path and prints what's left, the folder the file is in.
What does dirname do?
dirname cuts the last part, the file's name, off a path and prints what's left: the folder it's in. Scripts use it with ${BASH_SOURCE[0]} to find their own folder. basename does the opposite and keeps only the name.
dirname /home/sam/terminal-practice/shuffler/stats.sh # /home/sam/terminal-practice/shuffler
dirname shuffler/mix-lib.sh # shuffler
dirname stats.sh # .
In a sentence
- “The script runs dirname on its own path to learn which folder it lives in.”
- “dirname turned /home/sam/terminal-practice/shuffler/stats.sh into the shuffler folder.”
Level: Apprentice · More Unix terms at this level
Updated