Wednesday, June 30, 2021

Get parent directory name of shell script

 pwd | rev | cut -d/ -f1 | rev


lets see arguments for cut used with above command

spliting delimeter is given to -d, in this case \

required argument is given to -f, in this case 1


rev is used to reverse the string because parent directory name is the first argumet from reverse of pwd.

No comments:

Post a Comment

Optimize you working enviorenment : Single command to create & move to a directory in linux (C Shell, Bash)

Usually move to a directory just after creating is bit of a anxious task specially if the directory name is too long. mkdir long-name-of...