Files and folders

The dirname command

From a full path, shows the folder that contains it (removes the last segment).

Syntax

dirname <ruta>

Copy-ready examples

$ dirname /etc/passwdThe folder
$ dirname /var/log/syslogNested path

You can try them in the browser terminal: it does not touch your computer.

Typical mistakes

  • For a path with no slashes it returns a dot, meaning the current folder.

Related commands

FAQ

Does dirname create folders?

No, it only computes the path. To create you use mkdir.

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course