Navigation

dirname

Prints the directory part of a path.

dirname strips the final path component and prints the containing directory, which is useful in scripts.

Syntax
dirname path

Arguments explained

  • Options adjust output or behavior.
  • Arguments name the files, services, hosts, or values the command should work with.

Common examples

Get containing directory
dirname /var/log/syslog

Prints /var/log.

Use with a script path
script_dir=$(dirname "$0")

Stores the script's directory part in a variable.

dirname Command
FieldDetails
Commanddirname
CategoryNavigation
Primary usePrints the directory part of a path.
Syntaxdirname path