代码之家  ›  专栏  ›  技术社区  ›  Roberto Aloi

更改到上一个目录的CD选项

  •  7
  • Roberto Aloi  · 技术社区  · 15 年前

    我完全是一个新手抨击脚本。 我记得有一种方法可以执行 cd 命令,自动返回到上一个目录(不带显式 cd ... ) 有什么想法吗?

    4 回复  |  直到 12 年前
        1
  •  13
  •   Aaron Digulla    15 年前

    如果您只想返回到最后一个目录,可以使用 cd - .

    如果你需要更多的地方回去,试试 pushd <dir> 而不是 cd <dir> )然后你可以回去 popd .

        2
  •  4
  •   Roberto Aloi    15 年前

    找到了!我可以把它作为一个子外壳来执行。

    嵌入在 括号作为子shell运行。

    来源: http://tldp.org/LDP/abs/html/subshells.html

        3
  •  1
  •   vstrien    15 年前

    此外,pushd和popd非常方便——它们表示在一堆目录位置上的操作——允许您“返回时间”。

        4
  •  1
  •   recluze    14 年前

    你也可以试试 cdargs 包裹。你可以在这里找到一个教程: http://www.csrdu.org/nauman/2011/01/16/helpful-tips-for-newbie-system-admins/

    总结:

    yum -y install compat-libstdc++-296
    wget http://www.skamphausen.de/downloads/cdargs/cdargs-1.31-1.i386.rpm
    rpm -ivh cdargs-1.31-1.i386.rpm
    updatedb
    source `locate cdargs-bash.sh`
    # you can use any method you like for locating this file and running it
    # also, you need to put it in the ~/.bash_profile to run it every time you login
    echo source `locate cdargs-bash.sh` >> ~/.bash_profile 
    cdb
    

    标记目录并四处移动:

    cd /etc/conf/httpd/ext/
    mark apaconf
    cd /usr/local/src/
    cdb apaconf
    

    查看链接以获取其他命令或搜索网络。