Written 1 Sep 2026. This is a how-to, not a product card.
See the folder path
After basename, dirname prints the folder path of a name, without the last name. You don't need extra software for this.
See the last name printed the last name of a path. Tonight you ask for the folder path: dirname. Dirname prints the folders before the last name. Start with one tiny practice file, then dirname ~/dirname-a.txt.
~ is home shorthand. The last name is the file name after the folders. dirname strips the last name and keeps the folder path. That is not basename. Basename prints the last name. That is see the last name. You are still only practicing in home on the computer. It does not need extra system software, htop, Grafana, or a NAS for this one job.
Skip until SSH already works
SSH from the couch should already get you a prompt. SSH means type commands from your laptop, on the house network. If the last name is what you want, that is see the last name. Skip basename as tonight's job. If the full path is what you want, that is see the full path. Skip realpath as tonight's job.
What this is
dirname prints the folder of a path (the folders before the last name). You make one tiny practice file, then type dirname ~/dirname-a.txt. Dirname prints the folder path only, without the last name. Stick with that safe peek: the home folder path (typically /home/YOURLOGIN), without the last name dirname-a.txt, then the prompt back. You don't need extra system software for this.
It is not basename. Basename prints the last name. It is not realpath. Realpath prints the full path. It is not pwd. Pwd prints the folder you sit in.
Practice dirname in home
SSH in. Make sure home is where you sit:
pwd
You want a path that ends in your login name. If not:
cd ~
Make one tiny practice file:
printf 'hello\n' > ~/dirname-a.txt
Print the folder path (tonight's job):
dirname ~/dirname-a.txt
You want the home folder path (typically /home/YOURLOGIN), without the last name dirname-a.txt. Then the prompt back. ~ was home shorthand. Dirname kept the folder path only. That is enough for tonight. Practice only in home.
Debian and Ubuntu usually already have dirname (coreutils). Don't make apt the job.
If dirname is missing, install coreutils:
sudo apt install coreutils
Then stop. That apt line is not the lesson.
When you are done looking, throw the practice name away with careful delete only. That is delete a file carefully. Skip rm -rf.
rm -i ~/dirname-a.txt
Useful extras, still home only
Optional extra: folder path of the root path:
dirname /
That peek prints /. Root has no extra folder above it. Don't make / required. You can stay on dirname ~/dirname-a.txt. Don't dump the whole / tree.
Optional extra: folder path of the folder you sit in, as a dot:
dirname .
That peek prints . (the folder you sit in, as a dot). Don't make pwd the job. Don't make . required.
Skip huge dumps as tonight's job. Skip dirname piped into rm. Dirname prints a folder path. Rm deletes files. Don't mix those jobs. Skip files under /etc, whole /, SSH folders, USB sticks, and /srv. Practice only in home.
Skip screen, tmux, htop, Grafana, and a NAS. Keep SSH on the house network: keep the computer on the house network. Don't forward port 22.
What this is not
This is not basename. Basename prints the last name. Dirname prints the folder path only. That is see the last name. It is not realpath. That is see the full path. It is not pwd. That is see which folder you are in.
What next
Need the shortcut target? See the shortcut target. Need the last name from a path? See the last name. Keep SSH on the house network: keep the computer on the house network. Don't forward port 22.
Skip
- Skip if SSH still fails. Finish SSH from the couch first.
- Skip huge dumps as tonight's job. Tonight: one tiny practice file.
- Skip
dirnamepiped intorm. Dirname prints a folder path. Don't mix delete into this drill. - Skip
basename,realpath, andpwdas tonight's job. Those notes already exist. - Skip apt as tonight's job. The coreutils aside is not the lesson.
- Skip htop, Grafana, a NAS, files under
/etc, and whole/. - Skip
rm -rf. Careful delete only: delete a file carefully. - Skip opening SSH to the internet. That is keep the computer on the house network. Don't forward port 22.
Sources
Debian: dirname(1). Ubuntu: dirname(1). Official pages only. For the last name, see see the last name. For the full path, see see the full path. For the folder you sit in, see see which folder you are in. For making a shortcut, see make a shortcut. For file size, date, and permissions, see see file size, date, and permissions. For words you type once, see put a short line into a file. For sending output, see send output into another command. For the login, see SSH from the couch.