Need to know the name of the directory located above the current, then even higher, etc. in BASH
For example, there is a directory:
/ home / Ochen / Glupiy / Vopros
I need to get a name: Glupiy
Then get the name even more top DIR: Ochen
Etc.
If for the current directory ( Vopros ) my BASH team
pwd | grep -o '[^/]*$'
was a square wheel, then the command for the directory that above ( Glupiy ) can be called names
pwd | grep -o [^/]* | sed -e '$!{h;d;}' -ex
For the directory, which is even higher, I did not think of anything :)
I need to somehow create such a BASH command, which I would be able to pull the name of the current, top, which is even higher, etc., directories.
If it is impossible to make a more or less universal team, then throw at me at least a team to get the name of the DIR 2 levels higher.
For example for: / home / Ochen / Glupiy / Vopros
get name: ochen