linux中的cp命令

來源:互聯網
上載者:User

標籤:cp   linux   

cp命令--檔案複製

目錄和檔案的複製命令

cp命令文法和參數:

cp [OPTION]...SOURCE...DIRECTORY

-a ALL 等價於dpR
-d
複製符號連結源檔案時,目標檔案也將建立符號連結執行源檔案的原始檔案
-p preserve 保留檔案屬性,屬主,屬組,許可權和時間
-r recursive 遞迴目錄下的子檔案

樣本:

[[email protected] ~]# ll /etc/services 

-rw-r--r-- 1 root root 362031 2006-02-23 /etc/services

[[email protected] ~]# stat /etc/services 

  File: “/etc/services”

  Size: 362031    Blocks: 728        IO Block: 4096   一般檔案

Device: fd00h/64768dInode: 2282597     Links: 1

Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)

Access: 2014-11-11 11:20:33.000000000 +0800

Modify: 2006-02-23 21:09:23.000000000 +0800

Change: 2014-10-21 15:21:26.000000000 +0800


[[email protected] ~]# cp -a /etc/services /tmp/services

[[email protected] ~]# ll /tmp/services 

-rw-r--r-- 1 root root 362031 2006-02-23 /tmp/services

[[email protected] ~]# stat /tmp/services 

  File: “/tmp/services”

  Size: 362031    Blocks: 728        IO Block: 4096   一般檔案

Device: fd00h/64768dInode: 1434761     Links: 1

Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)

Access: 2014-11-11 11:20:33.000000000 +0800

Modify: 2006-02-23 21:09:23.000000000 +0800

Change: 2014-11-11 11:44:39.000000000 +0800

說明:檔案的所有屬性和許可權都拷貝過來了,並且ctime發生了改變


擴充:源檔案複製到目標目錄中提示檔案已經存在,如何直接覆蓋掉目標檔案?而讓系統不提示覆蓋呢?

[[email protected] ~]# cp -a /etc/services /tmp/

cp:是否覆蓋“/tmp/services”? 

在指令碼中是不能人工參與互動,解決方案:

  1. [[email protected] ~]# \cp -a /etc/services /tmp/services

  2. [[email protected] ~]# unalias cp 
    [[email protected] ~]# cp -a /etc/services /tmp/

  3. [[email protected] ~]# /bin/cp -a /etc/services /tmp/services
    說明:預設情況下,cp= cp -i 然而-i參數是提示覆蓋的意思


本文出自 “linux營運分享” 部落格,請務必保留此出處http://liangey.blog.51cto.com/9097868/1575258

linux中的cp命令

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.