1. 程式人生 > >2.6 相對和絕對路徑 2.7 cd命令 2.8 創建和刪除目錄2.9 rm命令

2.6 相對和絕對路徑 2.7 cd命令 2.8 創建和刪除目錄2.9 rm命令

ado mdi 51cto etc col 例如 sco images 圖片

絕對路徑的概念:
從“/”開始的均為絕對路徑,例如我們常用的網卡配置文件/etc/sysconfig/network-scripts/ifcfg-ens33,這就是一個絕對路徑文件。
相對路徑的概念:
不是以“/”開始,而是相對於現在的路徑

cd命令
切換目錄的命令。
命令格式:
cd[目錄名] 切換當前目錄至dir目錄名
cd - 是上一次的目錄
技術分享圖片
cd ~是進入家目錄
[root@localhost tmp]# cd ~
[root@localhost ~]# cd /
cd ..進入上一級目錄
[root@localhost /]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cd ..

[root@localhost sysconfig]# cd ..
[root@localhost etc]# cd ..
[root@localhost /]# cd ..
[root@localhost /]#

mkdir創建目錄命令
[root@localhost ~]# mkdir /tmp/aminglinux/
[root@localhost ~]# ll /tmp/aminglinux/
總用量 0
[root@localhost ~]# ll -d /tmp/aminglinux/
drwxr-xr-x. 2 root root 6 12月 17 17:18 /tmp/aminglinux/
[root@localhost ~]#

加參數-p,可以遞歸創建
[root@localhost ~]# mkdir -p /tmp/aminglinux/1/2/3
[root@localhost ~]# ll -d /tmp/aminglinux/1/2/3
drwxr-xr-x. 2 root root 6 12月 17 17:21 /tmp/aminglinux/1/2/3
在遞歸創建的時候加參數-pv,可視化進程
[root@localhost ~]# mkdir -pv /tmp/aminglinux/4/5/6
mkdir: 已創建目錄 "/tmp/aminglinux/4"
mkdir: 已創建目錄 "/tmp/aminglinux/4/5"
mkdir: 已創建目錄 "/tmp/aminglinux/4/5/6"
[root@localhost ~]#
刪除目錄的命令rmdir
[root@localhost ~]# rmdir /tmp/aminglinux/1
rmdir: 刪除 "/tmp/aminglinux/1" 失敗: 目錄非空
從上面的提示可以看出,rmdir只能刪除空目錄,如果裏面有文件或者其他目錄,那麽它將不能刪除。如果要刪除這個文件夾,必須要將文件夾裏面的全部東西都刪除。

刪除命令rm
[root@localhost ~]# rm /tmp/aminglinux/1/3.txt
rm:是否刪除普通空文件 "/tmp/aminglinux/1/3.txt"?
你在刪除文件或目錄的時候他會詢問你是否刪除,如果單個的文件可以,如果文件很多的話那就會很麻煩。這時我們在命令後面加參數-f,就不會再詢問了[root@localhost ~]# rm -f /tmp/aminglinux/1/3.txt
[root@localhost ~]#
[root@localhost ~]# rm -r /tmp/aminglinux/1/2/3/
rm:是否刪除目錄 "/tmp/aminglinux/1/2/3/"?
這樣刪除還是會先詢問,我們在加參數-f,這樣就不會再有詢問的提示了
[root@localhost ~]# rm -fr /tmp/aminglinux/1/2/3/
[root@localhost ~]#
工作中先可以利用mv移走,如果不出問題可以rm刪除,不建議用rm直接刪除。

2.6 相對和絕對路徑 2.7 cd命令 2.8 創建和刪除目錄2.9 rm命令