Linux 命令行快速切换回切换目录之前的目录

看到这个标题,是不是感觉有点绕?Linux 下的 cd (change directory)命令相信大家都用过,虽然不敢说是大家使用最多的命令,但至少算使用最多之一的了吧!

快速切换回切换目录之前的目录(cd -)

[root@master ruby_learning]# pwd
/root/ruby_learning
[root@master ruby_learning]# cd /usr/local/src/
[root@master src]# pwd
/usr/local/src
[root@master src]# cd -
/root/ruby_learning
[root@master ruby_learning]# pwd
/root/ruby_learning

快速切换回用户 home 目录(cd ~)

如果是 root 用户,home 目录就是 /root, 如果不是 root 用户,home 目录就是 /home/<username> 目录

[root@master ruby_learning]# cd ~
[root@master ~]# pwd
/root


[looking@master ruby_learning]$ pwd
/home/looking/ruby_learning
[looking@master ruby_learning]$ cd ~
[looking@master ~]$ pwd
/home/looking
[looking@master ~]$ 

快速切换回上级目录(cd ..)

[root@master ruby_learning]# pwd
/root/ruby_learning
[root@master ruby_learning]# cd ..
[root@master ~]# pwd
/root

猜你喜欢

转载自blog.csdn.net/TomorrowAndTuture/article/details/107824581