向上跳目录的小脚本 (linux/bash)

来源: http://syre.blogbus.com/logs/49837548.html

在很深的目录里的时候, 要往上跳n级, 就要敲很多键盘。 可以用如下脚本快捷实现, 加在.bashrc里

up(){
    i=$1
    if [ -z $i ]; then
        i=1
    fi
    p=''
    while (($i>0)); do
        p="../$p"
        (( i-- ))
    done
    cd $p
}

用法: up [levels]。 比如 up 2 就会向上跳两级目录。 不加参数, 就往上一级, 相当于 cd .. 。

snippets/updir.txt · 最后更改: 2010/05/26 01:18 由 lostsnow
 
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki