cd 命令

     Linux cd 命令可以說是Linux中最基本的命令語句,其他的命令語句要進行操作,都是建立在使用 cd 命令上的。
所以,學習Linux 常用命令,首先就要學好 cd 命令的使用方法技巧。
   1. 命令格式:
cd [目錄名]
   2. 命令功能:
切換當前目錄至dirName
   3. 常用範例
3.1 例一:進入系統根目錄
命令:
cd /
輸出:
[root@localhost ~]# cd /  
說明:進入系統根目錄,上面命令執行完後拿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 /

說明:
進入系統根目錄可以使用“ cd .. ”一直退,就可以到達根目錄
命令:
cd ../.. //
輸出:

1 [root@localhost soft]# pwd
2 /opt/soft
3 [root@localhost soft]# cd ../.. //
4 [root@localhost /]# pwd
5 /
6 [root@localhost /]#



說明:使用cd 命令實現進入當前目錄的父目錄的父目錄。
例2:使用 cd 命令進入當前用戶主目錄
“當前用戶主目錄”和“系統根目錄”是兩個不同的概念。進入當前用戶主目錄有兩個方法。
命令1:
cd
輸出:
1 [root@localhost soft]# pwd
2 /opt/soft
3 [root@localhost soft]# cd
4 [root@localhost ~]# pwd
5 /root
命令2:
cd ~
輸出:

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      

例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]#

說明:
跳轉到指定目錄,從根目錄開始,目錄名稱前加 / ,當前目錄內的子目錄直接寫名稱即可
例四:返回進入此目錄之前所在的目錄
命令:
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]#

例五:把上個命令的參數作爲cd參數使用。
命令:
cd !$
輸出:

1 [root@localhost soft]# cd !$
2 cd -
3 /root
4 [root@localhost ~]# cd !$
5 cd -
6 /opt/soft
7 [root@localhost soft]#

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章