• <output id="aynwq"><form id="aynwq"><code id="aynwq"></code></form></output>

    <mark id="aynwq"><option id="aynwq"></option></mark>
  • <mark id="aynwq"><option id="aynwq"></option></mark><label id="aynwq"><dl id="aynwq"></dl></label>
  • 學(xué)習(xí)啦>學(xué)習(xí)電腦>操作系統(tǒng)>Linux教程>

    Linux cp命令中拷貝所有的寫法

    時(shí)間: 志藝942 分享

      cp指令用于復(fù)制文件或目錄,如同時(shí)指定兩個(gè)以上的文件或目錄,且最后的目的地是一個(gè)已經(jīng)存在的目錄,則它會(huì)把前面指定的所有文件或目錄復(fù)制到此目錄中。接下來(lái)是小編為大家收集的Linux cp命令中拷貝所有的寫法,歡迎大家閱讀:

      Linux cp命令中拷貝所有的寫法

      一、預(yù)備

      cp就是拷貝,最簡(jiǎn)單的使用方式就是:

    1
    cp oldfile newfile

      但這樣只能拷貝文件,不能拷貝目錄,所以通常用:

    1
    cp -r old/ new/

      那就會(huì)把old目錄整個(gè)拷貝到new目錄下。注意,不是把old目錄里面的文件拷貝到new目錄,而是把old直接拷貝到new下面,結(jié)果是:

    1
    2
    3
    [root@dc5 test]# ll new/
    total 4
    drwxr-xr-x 2 root root 4096 Dec 15 11:55 old

      那如果要保持源文件的所有權(quán)限,可以這樣:

    1
    cp -rp old/ new/

      -p參數(shù),可以保持權(quán)限、宿主、時(shí)間棧,還可能包括link等;還有更簡(jiǎn)單的,就是用:

    1
    cp -a old/new/

      -a參數(shù),就等于-dpR。

      二、問(wèn)題1

      好,我們來(lái)看看這次的問(wèn)題。環(huán)境是:

      ◎兩個(gè)目錄:old、new,其中old里面有個(gè)三個(gè)內(nèi)容:test1文件、test2目錄,還有就是.test3,這是一個(gè)隱含文件。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    [root@dc5 test]# ll -laR
    .:
    total 20
    drwxr-xr-x 4 root root 4096 Dec 15 11:55 .
    drwxrwxrwt 7 root root 4096 Dec 15 11:59 ..
    drwxr-xr-x 2 root root 4096 Dec 15 12:14 new
    drwxr-xr-x 3 root root 4096 Dec 15 12:14 old
     
    ./new:
    total 8
    drwxr-xr-x 2 root root 4096 Dec 15 12:14 .
    drwxr-xr-x 4 root root 4096 Dec 15 11:55 ..
     
    ./old:
    total 12
    drwxr-xr-x 3 root root 4096 Dec 15 12:14 .
    drwxr-xr-x 4 root root 4096 Dec 15 11:55 ..
    -rw-r--r-- 1 root root 0 Dec 15 12:07 .test3
    -rw-r--r-- 1 root root 0 Dec 15 12:05 test1
    drwxr-xr-x 2 root root 4096 Dec 15 12:14 test2
     
    ./old/test2:
    total 8
    drwxr-xr-x 2 root root 4096 Dec 15 12:14 .
    drwxr-xr-x 3 root root 4096 Dec 15 12:14 ..

      ◎操作一:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    [root@dc5 test]# cp -a old/* new/
    [root@dc5 test]# ll -laR new/
    new/:
    total 12
    drwxr-xr-x 3 root root 4096 Dec 15 12:15 .
    drwxr-xr-x 4 root root 4096 Dec 15 11:55 ..
    -rw-r--r-- 1 root root 0 Dec 15 12:05 test1
    drwxr-xr-x 2 root root 4096 Dec 15 12:14 test2
     
    new/test2:
    total 8
    drwxr-xr-x 2 root root 4096 Dec 15 12:14 .
    drwxr-xr-x 3 root root 4096 Dec 15 12:15 ..

      問(wèn)題出來(lái)了:隱含的.test3文件沒(méi)有一齊拷貝到new目錄下。

      原因是:參數(shù)使用不正確。這樣的寫法,通常都是因?yàn)槭煜ち诉^(guò)去Dos的格式(包括我自己),而實(shí)際在bash環(huán)境下,cp使用是不能匹配類似.開(kāi)頭的隱含文件的。

      ◎操作二

      正確的寫法應(yīng)該這樣:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    [root@dc5 test]# cp -a old/. new/
    [root@dc5 test]# ll -laR new/
    new/:
    total 12
    drwxr-xr-x 3 root root 4096 Dec 15 12:14 .
    drwxr-xr-x 4 root root 4096 Dec 15 11:55 ..
    -rw-r--r-- 1 root root 0 Dec 15 12:07 .test3
    -rw-r--r-- 1 root root 0 Dec 15 12:05 test1
    drwxr-xr-x 2 root root 4096 Dec 15 12:14 test2
     
    new/test2:
    total 8
    drwxr-xr-x 2 root root 4096 Dec 15 12:14 .
    drwxr-xr-x 3 root root 4096 Dec 15 12:14 ..

      不用*號(hào),而用.號(hào)代替。

      還有一種比較復(fù)雜一些的寫法:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    [root@dc5 test]# cp -a old/* old/.[^.]* new/
    [root@dc5 test]# ll -laR new/
    new/:
    total 12
    drwxr-xr-x 3 root root 4096 Dec 15 12:25 .
    drwxr-xr-x 4 root root 4096 Dec 15 11:55 ..
    -rw-r--r-- 1 root root 0 Dec 15 12:07 .test3
    -rw-r--r-- 1 root root 0 Dec 15 12:05 test1
    drwxr-xr-x 2 root root 4096 Dec 15 12:14 test2
     
    new/test2:
    total 8
    drwxr-xr-x 2 root root 4096 Dec 15 12:14 .
    drwxr-xr-x 3 root root 4096 Dec 15 12:25 ..

      請(qǐng)注意寫法,不要寫成.*了。(原因請(qǐng)看下面)

      三、問(wèn)題2

      上面提到不要寫成.,那.代表什么?

    1
    2
    [root@dc5 test]# echo .*
    . ..

      .*代表的是當(dāng)前目錄,以及上一層目錄。

      所以,使用.*會(huì)導(dǎo)致更大的問(wèn)題:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    [root@dc5 test]# cp -a old/.* new/
    cp: cannot copy a directory, `old/..', into itself, `new/'
    cp: cannot copy a directory, `old/..', into itself, `new/'
    cp: will not create hard link `new/old' to directory `new/.'
    cp: overwrite `new/.test3'? y
    [root@dc5 test]# ll -laR new/
    new/:
    total 16
    drwxr-xr-x 4 root root 4096 Dec 15 11:55 .
    drwxr-xr-x 4 root root 4096 Dec 15 11:55 ..
    -rw-r--r-- 1 root root 0 Dec 15 12:07 .test3
    drwxr-xr-x 2 root root 4096 Dec 15 12:14 new
    -rw-r--r-- 1 root root 0 Dec 15 12:05 test1
    drwxr-xr-x 2 root root 4096 Dec 15 12:14 test2
     
    new/new:
    total 8
    drwxr-xr-x 2 root root 4096 Dec 15 12:14 .
    drwxr-xr-x 4 root root 4096 Dec 15 11:55 ..
    -rw-r--r-- 1 root root 0 Dec 15 12:07 .test3
    -rw-r--r-- 1 root root 0 Dec 15 12:05 test1
     
    new/test2:
    total 8
    drwxr-xr-x 2 root root 4096 Dec 15 12:14 .
    drwxr-xr-x 4 root root 4096 Dec 15 11:55 ..

      也就是說(shuō),使用.*就等于這樣了:

    1
    2
    3
    [root@dc5 test]# cp -a old/. old/.. old/.test3 new/
    [root@dc5 test]# echo old/.*
    old/. old/.. old/.test3

      
    看了“Linux cp命令中拷貝所有的寫法”還想看:

    1.linux cp命令使用介紹

    2.Linux下如何使用cp命令

    3.Linux中cp和scp命令怎么使用

    4.Linux使用cp命令進(jìn)行強(qiáng)制覆蓋的方法

    2919066 主站蜘蛛池模板: 中文字幕精品亚洲无线码一区 | 人人影院免费大片| 国产高清在线不卡| www.11yinyuan.com| 成人久久精品一区二区三区| 久久久久久久久久久福利| 日韩欧美亚洲一区二区综合| 亚洲人成影院在线无码按摩店 | 吃奶摸下激烈免费视频免费| 跳d放在里面逛超市的视频| 国产对白真实伦视频在线| 日本特黄特色特爽大片老鸭| 国产精品人成在线播放新网站| 91成人午夜在线精品| 在线中文字幕网站| 99久久国产综合精品麻豆| 天天射综合网站| bbbbbbbbb欧美bbb| 天天影院良辰美景好时光电视剧| yy6080影院| 女同志videos| ljr绿巨人地址| 天天操天天干天天射| freehd麻豆| 大量精子注入波多野结衣| av网站免费线看| 在线播放免费播放av片| 99久久综合狠狠综合久久| 国自产拍亚洲免费视频| 9420免费高清在线视频| 国产美女无遮挡免费视频| 7m精品福利视频导航| 国产精品极品美女免费观看| 2019天堂精品视频在线观看| 国产精品手机在线亚洲| 手机看片福利永久国产日韩| 国产福利一区二区三区在线观看| 日韩精品一区二区三区中文精品 | 精品一区二区久久久久久久网站 | 黄色一级毛片免费| 国产伦精品一区二区三区|