cd [目錄名]
切換當(dāng)前目錄至 [目錄名]
命令:
cd /
說明:進(jìn)入系統(tǒng)根目錄,上面命令執(zhí)行完后拿ls命令看一下linux命令,當(dāng)前目錄已經(jīng)到系統(tǒng)根目錄了
輸出:
hc@hc-virtual-machine:~$ pwd
/home/hc
hc@hc-virtual-machine:~$ cd /
hc@hc-virtual-machine:/$ ls
bin dev initrd.img lib64 mnt root snap sys var
boot etc initrd.img.old lost+found opt run srv tmp vmlinuz
cdrom home lib media proc sbin swapfile usr
pwd的作用是查詢當(dāng)前所在目錄
命令:
cd ..
輸出:
hc@hc-virtual-machine:~/PycharmProjects$ pwd
/home/hc/PycharmProjects
hc@hc-virtual-machine:~/PycharmProjects$ cd ..
hc@hc-virtual-machine:~$ pwd
/home/hc
命令:
cd ../..
輸出:
hc@hc-virtual-machine:~/PycharmProjects$ pwd
/home/hc/PycharmProjects
hc@hc-virtual-machine:~/PycharmProjects$ cd ../..
hc@hc-virtual-machine:/home$ pwd
/home
“當(dāng)前用戶主目錄”和“系統(tǒng)根目錄”是兩個(gè)不同的概念。進(jìn)入當(dāng)前用戶主目錄有兩個(gè)方法。
命令1:
cd
直接輸入cd,然后回車
輸出:
hc@hc-virtual-machine:~/PycharmProjects/my_test$ pwd
/home/hc/PycharmProjects/my_test
hc@hc-virtual-machine:~/PycharmProjects/my_test$ cd
hc@hc-virtual-machine:~$ pwd
/home/hc
上面的命令是我在非root用戶下操作的linux命令,現(xiàn)在我切換到root用戶下再操作一遍
hc@hc-virtual-machine:~/PycharmProjects/my_test$ sudo su
root@hc-virtual-machine:/home/hc/PycharmProjects/my_test# pwd
/home/hc/PycharmProjects/my_test
root@hc-virtual-machine:/home/hc/PycharmProjects/my_test# cd
root@hc-virtual-machine:~# pwd
/root
命令2:
cd ~
輸出
hc@hc-virtual-machine:~/PycharmProjects/my_test$ pwd
/home/hc/PycharmProjects/my_test
hc@hc-virtual-machine:~/PycharmProjects/my_test$ cd ~
hc@hc-virtual-machine:~$ pwd
/home/hc
命令
下一個(gè)教程:Linux 常用命令1