/home/myuser/dir_1/sub_1/sub_2/sub_3
我想从sub_3遍历到dir_1,我需要做的是
cd ../../..
我的问题是,是不是有更短的东西?我的意思是:
cd -t 3
在哪里可以告诉shell你想要返回多少个目录.
cdup() { # $1=number of times,defaults to 1 local path printf -v path '%*s' "${1:-1}" cd "${path// /../}" }
用于:
cdup 4 # to go up four directories cdup 1 # to explicitly go up one directory cdup # to implicitly go up one
不管N有多大,都有一次调用cd的好属性.