Cd-Command
cd 3 次到曾祖父母目錄
我有這個:
cd $(dirname $(dirname $(dirname "$0"))) &&
這將 cd 到項目根目錄。
是否有某種速記方式,我可以像這樣:
cd 3 && # not quite, but you get the idea
或者別的什麼,我的意思是你為什麼不知道?
也許這樣的命令是理想的:
cdx 3 &&
因為
cd
不知道 3 不是文件或目錄。
您知道這
cd ..
會將您帶到父目錄嗎?因此,如果我正確理解您的問題,您可以使用:cd $(dirname $0)/../../..
定義這個函式:
dirx(){ a=$0;for((i=0;i<$1;i++));do a=${a%/*};done;cd "$a"; }
並做:
$ dirx 3