2

I am trying to get the directory name of this file, which is not located in my current directory:

/home/me/PhD/file.tsv

when I run:

dirname /home/me/PhD/file.tsv

I get:

/home/me/PhD/

But, I would like to obtain just: PhD

How can I do this?

Jeni
  • 123
  • 6

1 Answers1

7
basename "$(dirname /home/me/PhD/file.tsv)"

Notes:

  • dirname and basename operate purely on strings. It doesn't matter if the path exists.
  • $() is explained here: What is $() in a command?