dirname command

dirname Command

  • dirname is mostly used in situations where you need to strip the last component from an absolute file name.
  • used to remove the trailing forward slashes “/” from the NAME and prints the remaining portion. If the argument NAME does not contain the forward-slash “/” then it simply prints dot “.”.


# dirname /home/example/foo/

output: /home/example

# dirname foo/file.txt

output: foo


Leave a Reply