中文字幕精品亚洲无线码二区,国产黄a三级三级三级看三级,亚洲七七久久桃花影院,丰满少妇被猛烈进入,国产小视频在线观看网站

每天一個linux命令(8):cp 命令

cp命令(ling)(ling)用(yong)來復制(zhi)文件或者(zhe)目(mu)錄,是(shi)(shi)Linux系(xi)統中最常用(yong)的(de)命令(ling)(ling)之一。一般情況下,shell會設置一個別名(ming),在命令(ling)(ling)行下復制(zhi)文件時,如(ru)果目(mu)標文件已經存在,就會詢問是(shi)(shi)否(fou)覆蓋,不管(guan)你是(shi)(shi)否(fou)使用(yong)-i參數。但(dan)是(shi)(shi)如(ru)果是(shi)(shi)在shell腳(jiao)本中執(zhi)行cp時,沒(mei)有(you)-i參數時不會詢問是(shi)(shi)否(fou)覆蓋。這說明(ming)命令(ling)(ling)行和shell腳(jiao)本的(de)執(zhi)行方(fang)式(shi)有(you)些(xie)不同(tong)。 

1.命令格式(shi):

用法:

   cp [選項]... [-T] 源 目的

       或:cp [選(xuan)項]... 源(yuan)... 目錄

       或:cp [選項(xiang)]... -t 目(mu)錄 源...

2.命令(ling)功能:

將源文(wen)件(jian)復制(zhi)至目(mu)標文(wen)件(jian),或將多個源文(wen)件(jian)復制(zhi)至目(mu)標目(mu)錄。

3.命令參數(shu):

-a, --archive    等于(yu)-dR --preserve=all

    --backup[=CONTROL    為(wei)每個(ge)已存在的(de)目標文件創建備份

-b     ;           類似--backup 但不接(jie)受參數

   ;--copy-contents        在(zai)遞歸處理是復制特殊文件內(nei)容

-d                等于--no-dereference --preserve=links

-f, --force        如果目(mu)標文件無法打開則(ze)將其移除并重試(當 -n 選項

                    存在時(shi)則不需(xu)再選此項)

-i, --interactive        覆蓋前(qian)詢(xun)問(使(shi)前(qian)面的 -n 選項失效)

-H        ;        跟隨源文件中的命(ming)令行(xing)符號鏈接

-l, --link    ;        鏈接文件(jian)而不(bu)復制

-L, --dereference   總是跟隨符號鏈接

-n, --no-clobber   不要覆(fu)蓋已存在的文件(使前面的 -i 選項失(shi)效)

-P, --no-dereference   不跟隨源文件中的(de)符號鏈(lian)接

-p                等于(yu)--preserve=模式(shi),所有權,時間戳

    --preserve[=屬(shu)性(xing)列表   保持指(zhi)定的(de)屬(shu)性(xing)(默認:模式(shi),所有權,時間戳(chuo)),如果(guo)

               可能保持附加屬性:環(huan)境、鏈(lian)接、xattr 等(deng)

-R, -r, --recursive  復制目(mu)(mu)錄及(ji)目(mu)(mu)錄內的所有(you)項目(mu)(mu)

4.命令實例:

實(shi)例一:復制單個文件(jian)到目(mu)(mu)標(biao)目(mu)(mu)錄(lu),文件(jian)在(zai)目(mu)(mu)標(biao)文件(jian)中不存(cun)在(zai)

命令:

cp log.log test5

輸出:

[root@localhost test]# cp log.log test5

[root@localhost test]# ll

-rw-r--r-- 1 root root    0 10-28 14:48 log.log

drwxr-xr-x 6 root root 4096 10-27 01:58 scf

drwxrwxrwx 2 root root 4096 10-28 14:47 test3

drwxr-xr-x 2 root root 4096 10-28 14:53 test5

[root@localhost test]# cd test5

[root@localhost test5]# ll

-rw-r--r-- 1 root root 0 10-28 14:46 log5-1.log

-rw-r--r-- 1 root root 0 10-28 14:46 log5-2.log

-rw-r--r-- 1 root root 0 10-28 14:46 log5-3.log

-rw-r--r-- 1 root root 0 10-28 14:53 log.log

說明(ming):

在(zai)沒有帶-a參數時,兩(liang)個(ge)文件的(de)(de)時間是不一樣的(de)(de)。在(zai)帶了-a參數時,兩(liang)個(ge)文件的(de)(de)時間是一致的(de)(de)。  

實例(li)二:目標(biao)文件存在時,會詢問是否覆蓋

命令:

cp log.log test5

輸出:

[root@localhost test]# cp log.log test5

cp:是(shi)否覆(fu)蓋“test5/log.log”? n

[root@localhost test]# cp -a log.log test5

cp:是否(fou)覆蓋“test5/log.log”? y

[root@localhost test]# cd test5/

[root@localhost test5]# ll

-rw-r--r-- 1 root root 0 10-28 14:46 log5-1.log

-rw-r--r-- 1 root root 0 10-28 14:46 log5-2.log

-rw-r--r-- 1 root root 0 10-28 14:46 log5-3.log

-rw-r--r-- 1 root root 0 10-28 14:48 log.log

說明:

目標文件(jian)存在時,會(hui)詢問(wen)是否(fou)(fou)覆(fu)蓋(gai)。這是因(yin)為cp是cp -i的別(bie)名(ming)。目標文件(jian)存在時,即使加了(le)-f標志,也還會(hui)詢問(wen)是否(fou)(fou)覆(fu)蓋(gai)。

實例三:復制整個目錄

命令:

輸出:

目(mu)標目(mu)錄存在時:

[root@localhost test]# cp -a test3 test5 

[root@localhost test]# ll

-rw-r--r-- 1 root root    0 10-28 14:48 log.log

drwxr-xr-x 6 root root 4096 10-27 01:58 scf

drwxrwxrwx 2 root root 4096 10-28 14:47 test3

drwxr-xr-x 3 root root 4096 10-28 15:11 test5

[root@localhost test]# cd test5/

[root@localhost test5]# ll

-rw-r--r-- 1 root root    0 10-28 14:46 log5-1.log

-rw-r--r-- 1 root root    0 10-28 14:46 log5-2.log

-rw-r--r-- 1 root root    0 10-28 14:46 log5-3.log

-rw-r--r-- 1 root root    0 10-28 14:48 log.log

drwxrwxrwx 2 root root 4096 10-28 14:47 test3

目標(biao)目錄不存(cun)在是:

[root@localhost test]# cp -a test3 test4

[root@localhost test]# ll

-rw-r--r-- 1 root root    0 10-28 14:48 log.log

drwxr-xr-x 6 root root 4096 ;10-27 01:58 scf

drwxrwxrwx 2 root root 4096 10-28 14:47 test3

drwxrwxrwx 2 root root 4096 10-28 14:47 test4

drwxr-xr-x 3 root root 4096 10-28 15:11 test5

[root@localhost test]#

說(shuo)明:

注意目標(biao)(biao)目錄存(cun)在(zai)與否結果是不(bu)一樣的。目標(biao)(biao)目錄存(cun)在(zai)時,整(zheng)個源目錄被復制到目標(biao)(biao)目錄里面。

 

實例四(si):復制的 log.log 建立一個(ge)連(lian)結(jie)檔 log_link.log

命令(ling):

cp -s log.log log_link.log

輸出:

[root@localhost test]# cp -s log.log log_link.log

[root@localhost test]# ll

lrwxrwxrwx 1 root root    7 10-28 15:18 log_link.log -> log.log

-rw-r--r-- 1 root root    0 10-28 14:48 log.log

drwxr-xr-x 6 root root 4096 10-27 01:58 scf

drwxrwxrwx 2 root root 4096 10-28 14:47 test3

drwxrwxrwx 2 root root 4096 10-28 14:47 test4

drwxr-xr-x 3 root root 4096 10-28 15:11 test5

說明:

那個 log_link.log 是由 -s 的參數(shu)造成的,建立的是一個『快捷方(fang)式』,所(suo)以您會看(kan)到在文件的最右邊,會顯示這個文件是『連結』到哪里去的!

posted @ 2012-10-29 08:12  peida  閱讀(236779)  評論(11)    收藏  舉報