目錄
- mkdir
- cd
- pwd
- rmdir
- cp
- mv
- rm
mkdir
解釋
命令名稱:mkdir
命令英文原意:make directories
命令所在路徑:/bin/mkdir
執行權限:所有用戶
功能描述:創建新目錄
語法
mkdir -p [目錄名]
-p 遞回創建
示例
# 在tmp下直接創建,此時Japan目錄不存在
mkdir /tmp/Japan/boduo
# 錯出現錯誤提示
[root@izm5e2q95pbpe1hh0kkwoiz ~]# mkdir /tmp/Japan/boduo
mkdir: cannot create directory ‘/tmp/Japan/boduo’: No such file or directory
# 此時需要遞回創建
mkdir -p /tmp/Japan/boduo
[root@izm5e2q95pbpe1hh0kkwoiz ~]# mkdir -p /tmp/Japan/boduo
# 同時創建多個目錄
mkdir /tmp/Japan/longze /tmp/Japan/cangjing
[root@izm5e2q95pbpe1hh0kkwoiz ~]# mkdir /tmp/Japan/longze /tmp/Japan/cangjing
[root@izm5e2q95pbpe1hh0kkwoiz ~]# mkdir /tmp/Japan/longze /tmp/Japan/cangjing
mkdir: cannot create directory ‘/tmp/Japan/longze’: File exists
mkdir: cannot create directory ‘/tmp/Japan/cangjing’: File exists
cd
解釋
命令名稱:cd
命令英文原意:change directory
命令所在路徑:shell內置命令
執行權限:所有用戶
功能描述:切換目錄
語法
cd [目錄]
示例
# 切換到boduo目錄下
cd /tmp/Japan/boduo
[root@izm5e2q95pbpe1hh0kkwoiz ~]# cd /tmp/Japan/boduo
[root@izm5e2q95pbpe1hh0kkwoiz boduo]#
# 回傳上一級目錄
cd ..
# 還是停留在當前目錄
cd .
pwd
解釋
命令名稱:pwd
命令英文原意:print working directory
命令所在路徑:/bin/pwd
執行權限:所有用戶
功能描述:顯示目錄完整路徑
語法
pwd
示例
# 切換到boduo目錄下
cd /tmp/Japan/boduo
[root@izm5e2q95pbpe1hh0kkwoiz ~]# cd /tmp/Japan/boduo
[root@izm5e2q95pbpe1hh0kkwoiz boduo]#
# 顯示當前目錄
[root@izm5e2q95pbpe1hh0kkwoiz boduo]# pwd
/tmp/Japan/boduo
rmdir
解釋
命令名稱:rmdir
命令英文原意:remove emptyg directories
命令所在路徑:/bin/rmdir
執行權限:所有用戶
功能描述:洗掉空目錄(有檔案無法洗掉)
語法
rmdir [目錄名]
示例
# 切換到boduo目錄下
cd /tmp/Japan/boduo
[root@izm5e2q95pbpe1hh0kkwoiz ~]# cd /tmp/Japan/boduo
[root@izm5e2q95pbpe1hh0kkwoiz boduo]#
# 創建檔案
touch a
# 有檔案時,移除boduo目錄,會報錯
[root@izm5e2q95pbpe1hh0kkwoiz boduo]# rmdir /tmp/Japan/boduo
rmdir: failed to remove ‘/tmp/Japan/boduo’: Directory not empty
# 洗掉檔案,之后,正常洗掉掉空目錄
[root@izm5e2q95pbpe1hh0kkwoiz boduo]# rm -f /tmp/Japan/boduo/a
[root@izm5e2q95pbpe1hh0kkwoiz boduo]# rmdir /tmp/Japan/boduo
cp
解釋
命令名稱:cp
命令英文原意:copy
命令所在路徑:/bin/cp
執行權限:所有用戶
功能描述:復制檔案或目錄
語法
cp -rp [原檔案或目錄] [目標目錄]
-r 復制目錄
-p 保留檔案屬性
示例
# 復制檔案,不用使用-r
cp /root/test /tmp
[root@izm5e2q95pbpe1hh0kkwoiz ~]# cp /root/test /tmp
# 復制目錄,需要使用-r
cp -r /tmp/Japan/boduo /root
[root@izm5e2q95pbpe1hh0kkwoiz ~]# cp /tmp/Japan/boduo /root
cp: omitting directory ‘/tmp/Japan/boduo’
[root@izm5e2q95pbpe1hh0kkwoiz ~]# cp -r /tmp/Japan/boduo /root
[root@izm5e2q95pbpe1hh0kkwoiz ~]# ls
boduo lnmp-install.log test
# 復制,保留檔案屬性
cp -p test /tmp
[root@izm5e2q95pbpe1hh0kkwoiz ~]# ls -l test
-rw-r--r-- 1 root root 11 Nov 27 10:35 test
# 之前的復制導致時間改變
[root@izm5e2q95pbpe1hh0kkwoiz ~]# ls -l /tmp/test
-rw-r--r-- 1 root root 11 Nov 28 15:32 /tmp/test
# 使用-p保留檔案的屬性
[root@izm5e2q95pbpe1hh0kkwoiz ~]# cp -p test /tmp
cp: overwrite ‘/tmp/test’? y
[root@izm5e2q95pbpe1hh0kkwoiz ~]# ls -l /tmp/test
-rw-r--r-- 1 root root 11 Nov 27 10:35 /tmp/test
# 同時復制多個檔案
cp lnmp-install.log test /tmp
[root@izm5e2q95pbpe1hh0kkwoiz ~]# pwd
/root
[root@izm5e2q95pbpe1hh0kkwoiz ~]# ls
boduo lnmp-install.log test
[root@izm5e2q95pbpe1hh0kkwoiz ~]# cp lnmp-install.log test /tmp
[root@izm5e2q95pbpe1hh0kkwoiz ~]# ls /tmp
Aegis-<Guid(5A2C30A2-A87D-490A-9281-6765EDAD7CBA)> mysql.sock
hsperfdata_root php-cgi.sock
Japan systemd-private-9255c5ee9ec84f5987c1d9ba485e177e-ntpd.service-eKcnmD
lnmp-install.log test
# 復制檔案的同時改變名字
cp test /tmp/test.txt
[root@izm5e2q95pbpe1hh0kkwoiz ~]# cp test /tmp/test.txt
[root@izm5e2q95pbpe1hh0kkwoiz ~]# ls -l /tmp/test.txt
-rw-r--r-- 1 root root 11 Nov 28 15:39 /tmp/test.txt
[root@izm5e2q95pbpe1hh0kkwoiz ~]#
[root@izm5e2q95pbpe1hh0kkwoiz ~]# cat test
test hhaha
[root@izm5e2q95pbpe1hh0kkwoiz ~]# cat /tmp/test.txt
test hhaha
mv
解釋
命令名稱:mv
命令英文原意:move
命令所在路徑:/bin/mv
執行權限:所有用戶
功能描述:剪切檔案/改名
語法
mv [原檔案或目錄] [目標目錄]
示例
# 剪切
mv /root/test.txt /tmp
# 剪切并改名
mv /root/test.txt /tmp/test1.txt
# 同目錄下改名
mv test.txt test1.txt
rm
解釋
命令名稱:rm
命令英文原意:remove
命令所在路徑:/bin/rm
執行權限:所有用戶
功能描述:洗掉檔案
語法
rm -rf [檔案或目錄]
-r 洗掉目錄
-f 強制執行
示例
# 洗掉單個檔案
rm test1.txt
[root@izm5e2q95pbpe1hh0kkwoiz ~]# rm test1.txt
rm: remove regular file ‘test1.txt’? y
# 強制洗掉單個檔案,不提示
rm -f test1.txt
# 強制洗掉tmp檔案夾及下面的內容,沒有提示
rm -rf /tmp
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/137642.html
標籤:Linux
上一篇:linux中檔案處理命令
下一篇:linux中的鏈接命令
