cd option to change to previous directory

怎甘沉沦 提交于 2019-12-07 00:16:51

问题


I'm a complete newbie to bash scripting. I remember there was a way to execute the cd command, automatically returning to the previous directory (without an explicit cd ...). Any idea?


回答1:


If you just want to go back to the last directory, you can use cd -.

If you need more places to go back to, try pushd <dir> (instead of cd <dir>) and then you can go back with popd.




回答2:


Found! I can execute it as a sub-shell.

A command list embedded between parentheses runs as a subshell.

SOURCE: http://tldp.org/LDP/abs/html/subshells.html




回答3:


Also, pushd and popd can come in very handy - they represent operations on a stack of directory locations - allowing you to "travel back in time".




回答4:


You can also try the cdargs package. You can find a tutorial here: http://www.csrdu.org/nauman/2011/01/16/helpful-tips-for-newbie-system-admins/

Summary:

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

Mark a directory and move around:

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

See the link for other commands or search the net.



来源:https://stackoverflow.com/questions/2408505/cd-option-to-change-to-previous-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!