cp 複製檔案或目錄
用法:cp [option] source原始檔 directory目標檔案,具體可以檢視 man cp
以常用的引數舉例
[root@hs-192-168-33-206 tom]# ll --full-time1.簡單複製 beauty 檔案總用量 24
-rwxr-xr-x 1 root root 0 2019-02-11 16:45:14.784189569 +0800 atext01
-rwxr-xr-x 1 tom root 4164 2019-02-11 10:50:32.965743579 +0800 beauty
drwxr-xr-x 5 root root 4096 2019-02-12 20:16:38.924928332 +0800 demo
-rwxr-xr-x 1 tom home 632 2019-02-11 10:47:48.732248707 +0800 hare
-rwxr-xr-x 1 tom home 118 2019-02-11 10:37:10.169390846 +0800 html
-rwxr-xr-x 1 tom home 136 2019-02-11 10:39:36.761673506 +0800 lesson
[root@hs-192-168-33-206 tom]# cp beauty beauty-201902142.加入 -a 完全複製beauty檔案, -a 引數相當於 -dpr 的組合[root@hs-192-168-33-206 tom]# ll --full-time
-rwxr-xr-x 1 tom root 4164 2019-02-11 10:50:32.965743579 +0800 beauty
-rwxr-xr-x 1 root root 4164 2019-02-14 15:31:35.141561785 +0800 beauty-20190214
[root@hs-192-168-33-206 tom]# cp -a beauty beautybak3.加入 -i 引數,在 demo 目錄下已經有 atext01檔案,加入-i,再次複製會先進行詢問,再操作[root@hs-192-168-33-206 tom]# ll --full-time
總用量 32
-rwxr-xr-x 1 tom root 4164 2019-02-11 10:50:32.965743579 +0800 beauty
-rwxr-xr-x 1 tom root 4164 2019-02-11 10:50:32.965743579 +0800 beautybak
[root@hs-192-168-33-206 tom]# cp -i atext01 ./demo/4.加入 -p 引數,連同檔案屬性一起被複製cp:是否覆蓋"./demo/atext01"?
[root@hs-192-168-33-206 tom]# cp -p hare hare.bak5.複製目錄,加入 -r 引數[root@hs-192-168-33-206 tom]# ll --full-time
總用量 28
-rwxr-xr-x 1 tom home 632 2019-02-11 10:47:48.732248707 +0800 hare
-rwxr-xr-x 1 tom home 632 2019-02-11 10:47:48.732248707 +0800 hare.bak
[root@hs-192-168-33-206 tom]# cp -r demo demobakrm 刪除檔案或目錄用法:rm [option] file 具體檢視 man rm[root@hs-192-168-33-206 tom]# ll --full-time
總用量 32
drwxr-xr-x 5 root root 4096 2019-02-14 15:37:08.866084027 +0800 demo
drwxr-xr-x 5 root root 4096 2019-02-14 15:51:24.815033641 +0800 demobak
#複製前後目錄裡檔案的對比,可以發現複製後檔案屬性發生了變化
#demo目錄下:
[root@hs-192-168-33-206 tom]# cd demo
[root@hs-192-168-33-206 demo]# ll --full-time
總用量 12
-rwxr-xr-x 1 root root 0 2019-02-14 15:40:27.083164877 +0800 atext01
drwxrwxrwx 2 root root 4096 2019-02-12 20:15:15.318993626 +0800 test
drwxr-xr-x 3 root root 4096 2019-02-12 20:16:38.924928332 +0800 test1
drwxr-xr-x 2 root root 4096 2019-02-12 20:09:58.473644928 +0800 work
#demobak目錄下:
[root@hs-192-168-33-206 tom]# cd demobak/
[root@hs-192-168-33-206 demobak]# ll --full-time
總用量 12
-rwxr-xr-x 1 root root 0 2019-02-14 15:51:24.814033621 +0800 atext01
drwxr-xr-x 2 root root 4096 2019-02-14 15:51:24.815033641 +0800 test
drwxr-xr-x 3 root root 4096 2019-02-14 15:51:24.815033641 +0800 test1
drwxr-xr-x 2 root root 4096 2019-02-14 15:51:24.814033621 +0800 work
-f:強制刪除1.刪除檔案-r:遞迴刪除,用於刪除目錄
-i:刪除前詢問,預設需要詢問
[root@hs-192-168-33-206 tom]# rm lesson012.刪除目錄rm:是否刪除普通檔案 "lesson01"?
#刪除目錄,如果不想詢問,可以使用 rm -rf 檔名mv 移動或重新命名檔案/目錄用法:mv [option] source directory[root@hs-192-168-33-206 tom]# rm -r demobak/
rm:是否進入目錄"demobak"? y
rm:是否刪除普通空檔案 "demobak/atext01"?y
rm:是否刪除目錄 "demobak/work"?y
rm:是否刪除目錄 "demobak/test"?y
rm:是否進入目錄"demobak/test1"? y
rm:是否進入目錄"demobak/test1/test2"? y
rm:是否刪除目錄 "demobak/test1/test2/test3"?y
rm:是否刪除目錄 "demobak/test1/test2"?y
rm:是否刪除目錄 "demobak/test1"?y
rm:是否刪除目錄 "demobak"?y
-f:強制刪除1.重新命名檔案-r:遞迴刪除,用於刪除目錄
-u:如果目標檔案比原始檔舊,才會去更新目標檔案
[root@hs-192-168-33-206 tom]# ll2.移動資料夾總用量 24
-rwxr-xr-x 1 root root 0 2月 11 16:45 atext01
[root@hs-192-168-33-206 tom]# mv atext01 atext02
[root@hs-192-168-33-206 tom]# ll
總用量 24
-rwxr-xr-x 1 root root 0 2月 11 16:45 atext02
[root@hs-192-168-33-206 tom]# mv -f demo ./test/demomvlinux -- 目錄基本操作(1)[root@hs-192-168-33-206 test]# ls
demomv
linux基本目錄操作命令
1.建立目錄 mkdir dir 選項 p 假如路徑上的目錄不存在,則會自動建立這些目錄 例子 mkdir p jdk jdk2 jdk3 建立3級路徑jdk jdk2 jdk3,假如無該路徑,則會自動建立沒有的目錄 2.刪除目錄 rmdir dir 選項 p 遞迴刪除dir目錄,當子目錄被刪除後,...
Linux 目錄基本操作 1
cd 切換目錄 1.切換到指定目錄下 cd 相對 絕對目錄 root localhost cd home tom demo root localhost demo 2.切換到某個使用者的主資料夾 root localhost cd tom root localhost tom 3.切換到自己的主資料...
Linux基本操作2
command 1 help command 2使用手冊 man command 3資訊頁 info command 例如 hash 命令 help hash hash 就是用某種特殊演算法提取某個檔案的特徵碼 比如某個人的指紋 就可以直接找到 hits 是指執行次數 快取命中,在快取中找到了 數字...