Dirname Command in Linux with Examples Last Updated : 16 Oct, 2024 Comments Improve Suggest changes Like Article Like Report dirname is a command in Linux that is used to remove the trailing forward slashes "/" from the NAME and print the remaining portion. If the argument NAME does not contain the forward slash "/" then it simply prints dot ".". In other words, we can say that the 'dirname' command is a useful tool for extracting the directory portion from a given path or filename. Syntax dirname [OPTION] NAMEWhere,NAME is the file or directory path from which the directory portion will be extracted.OPTION allows for additional functionality such as version checking or line-ending control.Basic Example: Extracting the Directory Name from a Full PathWe know that it is used to extract the directory name from a given file path.dirname /Desktop/root/bash.shdirname /Desktop/root/bash.shHere we can see that our whole path is "/Desktop/root/bash.sh", where we have an output "/Desktop/root" which is our directory name, and "bash.sh" was our file name.dirname bash.shdirname bash.shHere we can see that no path is mentioned on file name "bash.sh" is mentioned. Our output shows "." which means that we are in the current directory.Common Options available for dirname Command 1. `-z or -zero` Option in `dirname` command in LinuxThis option provides a way to end the line by a null command rather than a new line. Using this the next command will execute on the same line rather than on the next line. Syntax:dirname -zero NAME or dirname --z NAMEExample:dirname -z /Desktop/root/bash.shdirname -z /Desktop/root/bash.shAs we can see we end the line with a null command rather than a new line.2. `--help` Option in `dirname` command in Linux It displays helpful information. dirname --helpdirname --help3. `--version` Option in `dirname` command in Linux It displays version information. dirname --versiondirname --versionConclusionIn this article we discussed the `dirname` command in Linux. Which provides a simple and effective way to extract the directory portion from a given file path or name. By going through this article one can understand that `dirname` command helps in manipulating and working with the file path efficiently. Comment More infoAdvertise with us D DrRoot_ Follow Improve Article Tags : Technical Scripter Linux-Unix Technical Scripter 2018 linux-command Linux-directory-commands +1 More Similar Reads curl Command in Linux with Examples curl is a command-line utility for transferring data to or from a server, employing a range of internet protocols such as HTTP, HTTPS, FTP, SCP, and SFTP.Whether you want to download a file, test a REST API, or simply verify that a website is up and running, curl is your best friend. It is accessed 5 min read cut command in Linux with examples The cut command in linux is a command for cutting out the sections from each line of files and writing the result to standard output. It can be used to cut parts of a line by byte position, character, and field. The cut command slices a line and extracts the text. It is necessary to specify an optio 8 min read cvs command in Linux with Examples In today's digital era, where file modifications and version control are essential, the Concurrent Versions System (CVS) command in Linux emerges as a powerful tool. CVS allows users to store and track the history of files, enabling easy retrieval of previous versions and restoring corrupted files. 6 min read How to Display and Set Date and Time in Linux | date Command Unlock the full potential of the date command in Linuxâa versatile tool that does more than just show the current date and time. With this command, you can set your systemâs clock, synchronize time across networks, and even calculate past or future dates for tasks like scheduling or logging. In this 8 min read dc command in Linux with examples The dc command is a versatile calculator found in Linux systems, operating using reverse Polish notation (RPN). This command allows users to perform arithmetic calculations and manipulate a stack, making it ideal for complex mathematical tasks directly from the command line.SyntaxThe basic syntax fo 3 min read 'dd' Command in Linux: Explained The dd command in Linux is a powerful utility for low-level data copying and conversion, primarily used for disk cloning, creating disk images, partition backups, and writing ISO files to USB drives. Mastering the dd command is essential for Linux system administrators, as it enables precise control 6 min read declare command in Linux with Examples The built-in is a powerful built-in feature of the Bash shell. It allows users to declare and set attributes for variables and functions, enabling better control over their behavior. By understanding how to use declare, you can manage variables and functions more effectively in your shell scripts. T 2 min read depmod command in Linux with examples depmod(Dependency Modules) command is used to generate a list of dependency description of kernel modules and its associated map files. This analyzes the kernel modules in the directory /lib/modules/kernel-release and creates a "Makefile"-like dependency file named modules.dep based on the symbols p 7 min read df Command in Linux with Examples There might come a situation while using Linux when you want to know the amount of space consumed by a particular file system on your LINUX system or how much space is available on a particular file system. LINUX being command friendly provides a command line utility for this i.e. 'df' command that 9 min read How to Compare Files Line by Line in Linux | diff Command In the world of Linux, managing and comparing files is a common task for system administrators and developers alike. The ability to compare files line by line is crucial for identifying differences, debugging code, and ensuring the integrity of data. One powerful tool that facilitates this process i 9 min read Like