每天一(yi)個linux命(ming)令(2):cd命(ming)令
Linux cd 命令可以說是Linux中最基本的命令語句,其他的命令語句要進行操作,都是建立在使用 cd 命令上的。
所以,學習Linux 常用命令,首先就要學好 cd 命令的使用方法技巧。
1. 命令格(ge)式:
cd [目錄名]
2. 命令功能:
切換當前目錄至dirName
3. 常(chang)用范例(li)
3.1 例一:進入系統根目錄
命(ming)令:
cd /
輸出:
[root@localhost ~]# cd /
說(shuo)明:進入系統根(gen)目錄,上面命令執行完后拿ls命令看一下,當前目錄已經到系統根目錄了
命令:
cd .. 或者 cd .. //
輸出:
1 [root@localhost soft]# pwd
2 /opt/soft
3 [root@localhost soft]# cd ..
4 [root@localhost opt]# cd ..//
5 [root@localhost /]# pwd
6 /
2 /opt/soft
3 [root@localhost soft]# cd ..
4 [root@localhost opt]# cd ..//
5 [root@localhost /]# pwd
6 /
說(shuo)明:
進入系統根目錄可以使用“ cd .. ”一直退,就可以到達根目錄
命令:
cd ../.. //
輸出:
1 [root@localhost soft]# pwd
2 /opt/soft
3 [root@localhost soft]# cd ../.. //
4 [root@localhost /]# pwd
5 /
6 [root@localhost /]#
2 /opt/soft
3 [root@localhost soft]# cd ../.. //
4 [root@localhost /]# pwd
5 /
6 [root@localhost /]#
說明:使用cd 命令實現進入當前目錄的父目錄的父目錄。
例2:使用 cd 命令進入當前用戶主目錄
“當(dang)前用戶主(zhu)目錄(lu)”和“系統根目錄(lu)”是(shi)兩個(ge)不(bu)同的概(gai)念。進入當(dang)前用戶主(zhu)目錄(lu)有兩個(ge)方法(fa)。
命令1:
cd
輸出:
1 [root@localhost soft]# pwd
2 /opt/soft
3 [root@localhost soft]# cd
4 [root@localhost ~]# pwd
5 /root
2 /opt/soft
3 [root@localhost soft]# cd
4 [root@localhost ~]# pwd
5 /root
命令2:
cd ~
輸出(chu):
1 [root@localhost ~]# cd /opt/soft/
2 [root@localhost soft]# pwd
3 /opt/soft
4 [root@localhost soft]# cd ~
5 [root@localhost ~]# pwd
6 /root
2 [root@localhost soft]# pwd
3 /opt/soft
4 [root@localhost soft]# cd ~
5 [root@localhost ~]# pwd
6 /root
例3:跳轉到指定目錄
命令:
cd /opt/soft
輸出:
1 [root@localhost ~]# cd /opt/soft
2 [root@localhost soft]# pwd
3 /opt/soft
4 [root@localhost soft]# cd jdk1.6.0_16/
5 [root@localhost jdk1.6.0_16]# pwd
6 /opt/soft/jdk1.6.0_16
7 [root@localhost jdk1.6.0_16]#
2 [root@localhost soft]# pwd
3 /opt/soft
4 [root@localhost soft]# cd jdk1.6.0_16/
5 [root@localhost jdk1.6.0_16]# pwd
6 /opt/soft/jdk1.6.0_16
7 [root@localhost jdk1.6.0_16]#
說明:
跳轉到指定目錄,從根目錄開始,目錄名稱前加 / ,當前目錄內的子目錄直接寫名稱即可
例四:返(fan)回進入此目(mu)錄之前所(suo)在的目(mu)錄
命令:
cd -
輸出:
1 [root@localhost soft]# pwd
2 /opt/soft
3 [root@localhost soft]# cd -
4 /root
5 [root@localhost ~]# pwd
6 /root
7 [root@localhost ~]# cd -
8 /opt/soft
9 [root@localhost soft]#
2 /opt/soft
3 [root@localhost soft]# cd -
4 /root
5 [root@localhost ~]# pwd
6 /root
7 [root@localhost ~]# cd -
8 /opt/soft
9 [root@localhost soft]#
例五(wu):把上個命令的參數(shu)作為cd參數(shu)使用。
命令(ling):
cd !$
輸出:
1 [root@localhost soft]# cd !$
2 cd -
3 /root
4 [root@localhost ~]# cd !$
5 cd -
6 /opt/soft
7 [root@localhost soft]#
2 cd -
3 /root
4 [root@localhost ~]# cd !$
5 cd -
6 /opt/soft
7 [root@localhost soft]#
關注 熵減黑客 ,一起學習成長
