Linux dirname command - output the name with the trailing "/" character part removed

The Linux dirname command is used to output the name with the trailing "/" character part removed.

Linux dirname command Function Description

Use the dirname command to output the name with the trailing "/" character removed; if the name does not contain a "/", "." is displayed (indicates the current directory).

The dirname command removes the non-directory part of the file name and displays only the contents related to the directory. dirname command reads the specified pathname retaining the last / and the characters after it, removes the rest, and writes the result to the standard output. If there are no characters after the last /, the dirname command uses the penultimate / and ignores all subsequent characters. dirname and basename are usually used interchangeably in shell internal commands to specify an output file name that differs slightly from the specified input file name.

Linux dirname command Syntax

dirname [name]
dirname [option]

Linux dirname command Examples

Common examples

dirname //
result is: /

dirname /a/b/
result is: /a

dirname a
result is: .

dirname a/b
result is: a

Name of the ccc.txt file output with the trailing "/" character part removed

dirname ccc.txt

Output:

Linux dirname command

Name for the output of /root/install.log file without the trailing "/" character part

[root@rhel ~]# dirname /root/install.log
/root
Like(0)

Related

Linux Login Logout Command
Linux login commandLinux logout commandLinux nologin commandLinux exit commandLinux sulogin commandLinux rlogin commandLinux poweroff commandLinux ctrlaltdel CommandLinux shutdown commandLinux halt commandLinux reboot commandLinux init commandLinux runlevel commandLinux telinit command
Linux File Management Command
Linux cat commandLinux tac commandLinux nl commandLinux more commandLinux less commandLinux head commandLinux tail commandLinux rev commandLinux fold commandLinux fmt commandLinux expand commandLinux pr commandLinux sort commandLinux uniq commandLinux cut commandLinux comm commandLinux diff commandLinux join commandLinux diff3 commandLinux cmp commandLinux colrm commandLinux paste commandLinux mkdir commandLinux tr commandLinux split commandLinux csplit commandLinux tee commandLinux unexpand commandLinux patch commandLinux awk commandLinux sed commandLinux od commandLinux pwd commandLinux cd commandLinux ls commandLinux dir commandLinux dirs commandLinux touch commandLinux rmdir commandLinux cp commandLinux mv commandLinux rm commandLinux install commandLinux tmpwatch commandLinux file commandLinux du commandLinux wc commandLinux tree commandLinux cksum commandLinux md5sum commandLinux sum commandLinux dirname commandLinux mkfifo Command
Cron Expressions
Cron Expression to Run Every Day at 12 PMUnderstanding Vue Cron ExpressionsUnderstanding JS Cron ExpressionsA Comprehensive Guide to Cron Expressions for Scheduled TasksUnderstanding Linux Cron ExpressionsUnderstanding Quartz Cron ExpressionsCron ExpressionCron Time ExpressionCron Expression ParsingCron Expression: Executing a Task Every SecondCron Expression for Every Minute ExecutionCron Expression to Execute Every 10 MinutesCron Expression: Executing Every HourCron Expression to Execute Once a YearCron Expression: How to Schedule a Task to Run Daily at Midnight?