8

Need get part of path, for example "/home/server/folder1/rev.1111/bin" Needed part is "rev.1111" I`ll try to parse by PWD & grep commands, but I am newbie on linux and I cant do this.

Roman
  • 1,163
  • 3
  • 9
  • 5
  • being a newbie does not mean you can not do anything before asking a question like this, your first stop should be http://www.gnu.org instead of here – ajreal Aug 15 '11 at 14:02

2 Answers2

14
pwd | awk -F/ '{print $(NF-1)}'
Sean Bright
  • 118,630
  • 17
  • 138
  • 146
  • 1
    This works great, thank you. You can also do it the otherway to piece together the front part of the path '{ print $1/$2/$3 }' etc. – Aaron Bonner Aug 02 '17 at 13:33
14

Using the basename & dirname commands:

basename $(dirname $(pwd))
Nicolae Dascalu
  • 3,425
  • 2
  • 19
  • 17