WebMasterCampus
WEB DEVELOPER Resources

Linux dirname Command

Learn Linux dirname Command with examples


Linux dirname Command

In Linux, we can use “dirname” strip last component from file name.

dirname Command Syntax

>> dirname [OPTION] NAME

Incase If the argument NAME does not contains the forward slash “/” then it simply prints dot “.”

dirname Command Example

>> dirname /etc/ssh/ssh_config.d

/etc/ssh

dirname -zero NAME or dirname –z NAME

This option provides a way to end the line by a null command rather then a new line.

Using this the next command will execute on the same line rather than on the next line.

>>  dirname -z /etc/ssh/ssh_config.d
/etc/ssh >> :~$

dirname –help

It displays help information.

>> dirname --help

dirname –version

It displays version information.

>> dirname --version 

dirname Command in Linux (Documentation)

~$ man dirname

NAME
       dirname - strip last component from file name

SYNOPSIS
       dirname [OPTION] NAME...

DESCRIPTION
       Output each NAME with its last non-slash component and trailing slashes removed; if NAME contains no /'s, out‐
       put '.' (meaning the current directory).

       -z, --zero
              end each output line with NUL, not newline

       --help display this help and exit

       --version
              output version information and exit

EXAMPLES
       dirname /usr/bin/
              -> "/usr"

       dirname dir1/str dir2/str
              -> "dir1" followed by "dir2"

       dirname stdio.h
              -> "."
Created with love and passion.