Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get basename of parent's parent's directory name in shell?

Tags:

linux

bash

shell

I want to get hold of the basename of the parent directory of the parent directory of the current directory in a shell script.

For example:

$ pwd
/home/tmp/terminal/env/1239754/control/state
$

I want to get this - 1239754.

like image 308
Insanitee Avatar asked May 31 '17 17:05

Insanitee


1 Answers

you can try this

basename `cd ../..; pwd`
like image 130
rolly4444 Avatar answered Oct 13 '22 18:10

rolly4444