Roman
Roman

Reputation: 1213

How to get part of path using linux commands

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.

Upvotes: 9

Views: 14410

Answers (2)

Nicolae Dascalu
Nicolae Dascalu

Reputation: 3535

Using the basename & dirname commands:

basename $(dirname $(pwd))

Upvotes: 15

Sean Bright
Sean Bright

Reputation: 120644

pwd | awk -F/ '{print $(NF-1)}'

Upvotes: 15

Related Questions