How to get part of path using linux commands

前端 未结 2 585
醉酒成梦
醉酒成梦 2021-01-12 16:18

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 lin

相关标签:
2条回答
  • 2021-01-12 17:09

    Using the basename & dirname commands:

    basename $(dirname $(pwd))
    
    0 讨论(0)
  • 2021-01-12 17:10
    pwd | awk -F/ '{print $(NF-1)}'
    
    0 讨论(0)
提交回复
热议问题