用法
用法:cp [選項(xiàng)]... [-T] 源文件 目標(biāo)文件
或:cp [選項(xiàng)]... 源文件... 目錄
或:cp [選項(xiàng)]... -t 目錄 源文件...
拷貝文件
cp /etc/hosts /home/
cp /opt/1.jpg /home/
拷貝文件夾
cp -r /opt/test/. /home/excel/test/
一般配合mkdir -p(創(chuàng)建文件夾) 使用
mkdir -p /home/test
命令詳細(xì)
用法:cp [選項(xiàng)]... [-T] 源文件 目標(biāo)文件
或:cp [選項(xiàng)]... 源文件... 目錄
或:cp [選項(xiàng)]... -t 目錄 源文件...
Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.
Mandatory arguments to long options are mandatory for short options too.
-a, --archive 等于-dR --preserve=all
--attributes-only 僅復(fù)制屬性而不復(fù)制數(shù)據(jù) --backup[=CONTROL 為每個(gè)已存在的目標(biāo)文件創(chuàng)建備份
-b 類似--backup 但不接受參數(shù)
--copy-contents 在遞歸處理是復(fù)制特殊文件內(nèi)容
-d 等于--no-dereference --preserve=links
-f, --force if an existing destination file cannot be
opened, remove it and try again (this option
is ignored when the -n option is also used)
-i, --interactive prompt before overwrite (overrides a previous -n
option)
-H follow command-line symbolic links in SOURCE
-l, --link hard link files instead of copying
-L, --dereference always follow symbolic links in SOURCE
-n, --no-clobber 不要覆蓋已存在的文件(使前面的 -i 選項(xiàng)失效)
-P, --no-dereference 不跟隨源文件中的符號(hào)鏈接
-p 等于--preserve=模式,所有權(quán),時(shí)間戳
--preserve[=屬性列表 保持指定的屬性(默認(rèn):模式,所有權(quán),時(shí)間戳),如果
可能保持附加屬性:環(huán)境、鏈接、xattr 等
-c deprecated, same as --preserve=context
--sno-preserve=屬性列表 不保留指定的文件屬性
--parents 復(fù)制前在目標(biāo)目錄創(chuàng)建來(lái)源文件路徑中的所有目錄
-R, -r, --recursive 遞歸復(fù)制目錄及其子目錄內(nèi)的所有內(nèi)容
--reflink[=WHEN] 控制克隆/CoW 副本。請(qǐng)查看下面的內(nèi)如。
--remove-destination 嘗試打開(kāi)目標(biāo)文件前先刪除已存在的目的地
文件 (相對(duì)于 --force 選項(xiàng))
--sparse=WHEN 控制創(chuàng)建稀疏文件的方式
--strip-trailing-slashes 刪除參數(shù)中所有源文件/目錄末端的斜杠
-s, --symbolic-link 只創(chuàng)建符號(hào)鏈接而不復(fù)制文件
-S, --suffix=后綴 自行指定備份文件的后綴
-t, --target-directory=目錄 將所有參數(shù)指定的源文件/目錄
復(fù)制至目標(biāo)目錄
-T, --no-target-directory 將目標(biāo)目錄視作普通文件
-u, --update 只在源文件比目標(biāo)文件新,或目標(biāo)文件
不存在時(shí)才進(jìn)行復(fù)制
-v, --verbose 顯示詳細(xì)的進(jìn)行步驟
-x, --one-file-system 不跨越文件系統(tǒng)進(jìn)行操作
-Z set SELinux security context of destination
file to default type
--context[=CTX] like -Z, or if CTX is specified then set the
SELinux or SMACK security context to CTX
--help 顯示此幫助信息并退出
--version 顯示版本信息并退出
默認(rèn)情況下,源文件的稀疏性僅僅通過(guò)簡(jiǎn)單的方法判斷,對(duì)應(yīng)的目標(biāo)文件目標(biāo)文件也
被為稀疏。這是因?yàn)槟J(rèn)情況下使用了--sparse=auto 參數(shù)。如果明確使用
--sparse=always 參數(shù)則不論源文件是否包含足夠長(zhǎng)的0 序列也將目標(biāo)文件創(chuàng)文
建為稀疏件。
使用--sparse=never 參數(shù)禁止創(chuàng)建稀疏文件。
當(dāng)指定了--reflink[=always] 參數(shù)時(shí)執(zhí)行輕量化的復(fù)制,即只在數(shù)據(jù)塊被修改的
情況下才復(fù)制。如果復(fù)制失敗或者同時(shí)指定了--reflink=auto,則返回標(biāo)準(zhǔn)復(fù)制模式。
The backup suffix is '~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX.
The version control method may be selected via the --backup option or through
the VERSION_CONTROL environment variable. Here are the values:
none, off 不進(jìn)行備份(即使使用了--backup 選項(xiàng))
numbered, t 備份文件加上數(shù)字進(jìn)行排序
existing, nil 若有數(shù)字的備份文件已經(jīng)存在則使用數(shù)字,否則使用普通方式備份
simple, never 永遠(yuǎn)使用普通方式備份
有一個(gè)特別情況:如果同時(shí)指定--force 和--backup 選項(xiàng),而源文件和目標(biāo)文件
是同一個(gè)已存在的一般文件的話,cp 會(huì)將源文件備份。
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。