在IT運維系統(tǒng)中,Linux是大家普遍了解的內容,而Linux的cd命令如何使用一直都是老生常談的話題,相信大家對于Linux的cd命令多多少少都有一定的了解。Linuxcd命令是Linux中最基本的命令語句,其他的命令語句要進行操作,都是建立在使用cd命令上的。那么Linux的cd命令如何使用?學習Linux常用命令,首先就要學好cd命令的使用方法技巧。
1.命令格式:
cd[目錄名]
2.命令功能:
切換當前目錄至dirName
3.常用范例
3.1例一:進入系統(tǒng)根目錄
命令:
cd/
輸出:
[root@localhost~]#cd/
說明:進入系統(tǒng)根目錄,上面命令執(zhí)行完后拿ls命令,當前目錄已經到系統(tǒng)根目錄
命令:
cd..或者cd..//
輸出:
[root@localhostsoft]#pwd
/opt/soft
[root@localhostsoft]#cd..
[root@localhostopt]#cd..//
[root@localhost/]#pwd
/
說明:
進入系統(tǒng)根目錄可以使用“cd..”一直退,就可以到達根目錄
命令:
cd../..//
輸出:
[root@localhostsoft]#pwd
/opt/soft
[root@localhostsoft]#cd../..//
[root@localhost/]#pwd
/
[root@localhost/]#
說明:使用cd命令實現(xiàn)進入當前目錄的父目錄的父目錄。
例2:使用cd命令進入當前用戶主目錄
“當前用戶主目錄”和“系統(tǒng)根目錄”是兩個不同的概念。進入當前用戶主目錄有兩個方法。
命令1:
cd
輸出:
[root@localhostsoft]#pwd
/opt/soft
[root@localhostsoft]#cd
[root@localhost~]#pwd
/root
命令2:
cd~
輸出:
[root@localhost~]#cd/opt/soft/
[root@localhostsoft]#pwd
/opt/soft
[root@localhostsoft]#cd~
[root@localhost~]#pwd
/root
例3:跳轉到指定目錄
命令:
cd/opt/soft
輸出:
[root@localhost~]#cd/opt/soft
[root@localhostsoft]#pwd
/opt/soft
[root@localhostsoft]#cdjdk1.6.0_16/
[root@localhostjdk1.6.0_16]#pwd
/opt/soft/jdk1.6.0_16
[root@localhostjdk1.6.0_16]#
說明:
跳轉到指定目錄,從根目錄開始,目錄名稱前加/,當前目錄內的子目錄直接寫名稱即可
例四:返回進入此目錄之前所在的目錄
命令:
cd–
輸出:
[root@localhostsoft]#pwd
/opt/soft
[root@localhostsoft]#cd-
/root
[root@localhost~]#pwd
/root
[root@localhost~]#cd-
/opt/soft
[root@localhostsoft]#
例五:把上個命令的參數(shù)作為cd參數(shù)使用。
命令:
cd!$
輸出:
#cd!$
cd-1[root@localhostsoft]#cd!$
cd-
/root
[root@localhost~]
/opt/soft
[root@localhostsoft]#
好了,關于Linux的cd命令如何使用介紹到這里就結束了。如果想了解更多關于Linux的信息,請繼續(xù)關注中培偉業(yè)。