把 SOURCE 拷貝到 DEST,或把多個 SOURCE 拷貝到 DIRECTORY。
cp -r /home/test /var cp -R /home/test /var
基本語法
cp [OPTION]... [-T] SOURCE DEST cp [OPTION]... SOURCE... DIRECTORY cp [OPTION]... -t DIRECTORY SOURCE...
注意:長選項強製性自變量,對於短選項也是強製性的。
OPTION 參數
| 參數 | EN 解釋 | 中文翻譯 | 備注 |
|---|---|---|---|
| -a, --archive | same as -dR --preserve=all | 如同 -dR --preserve=all | |
| --attributes-only | don't copy the file data, just the attributes | 不拷貝文件數據,僅拷貝屬性 | |
| --backup[=CONTROL] | make a backup of each existing destination file | 對每個現有目的地文件進行備份 | |
| -b | like --backup but does not accept an argument | 類似 --backup,但不接受自變量 | |
| --copy-contents | copy contents of special files when recursive | 拷貝特殊文件的內容,當遞歸時 | |
| -d | same as --no-dereference --preserve=links | 如同 --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) |
若現有目的地文件無法被打開, 則移除它並再次重試 (此選項會被忽略,當還使用 -n 選項時) |
|
| -i, --interactive | prompt before overwrite (overrides a previous -n option) | 覆寫前提示 (覆蓋之前的 -n 選項) | |
| -H | follow command-line symbolic links in SOURCE | 遵循 SOURCE 中的命令行符號鏈接 | |
| -l, --link | hard link files instead of copying | 硬鏈接文件,代替拷貝 | |
| -L, --dereference | always follow symbolic links in SOURCE | 始終遵循 SOURCE 中的符號鏈接 | |
| -n, --no-clobber | do not overwrite an existing file (overrides a previous -i option) | 不覆寫現有文件 (覆蓋之前的 -i 選項) | |
| -P, --no-dereference | never follow symbolic links in SOURCE | 從不遵循 SOURCE 中的符號鏈接 | |
| -p | same as --preserve=mode,ownership,timestamps | 如同 --preserve=mode,ownership,timestamps | |
| --preserve[=ATTR_LIST] |
preserve the specified attributes (default: mode,ownership,timestamps), if possible additional attributes: context, links, xattr, all |
保留指定屬性 (默認:模式 所有權 時間 時間戳), 若可能的話,補充屬性:上下文 鏈接 xattr 所有 |
|
| --no-preserve=ATTR_LIST | don't preserve the specified attributes | 不保留指定的屬性 | |
| --parents | use full source file name under DIRECTORY | 在目錄下使用完整的源文件名 | |
| -R, -r, --recursive | copy directories recursively | 遞歸拷貝目錄 | |
| --reflink[=WHEN] | control clone/CoW copies. See below | 控製剋隆/CoW 拷貝 | |
| --remove-destination |
remove each existing destination file before attempting to open it (contrast with --force) |
移除每個現有目的地文件,在嘗試打開它之前 (與 --force 對比) |
|
| --sparse=WHEN | control creation of sparse files. See below | 控製稀疏文件的創建 | |
| --strip-trailing-slashes | remove any trailing slashes from each SOURCE argument | 從每個 SOURCE 自變量中移除任何結尾斜杠 | |
| -s, --symbolic-link | make symbolic links instead of copying | 生成符號鏈接,而不是拷貝 | |
| -S, --suffix=SUFFIX | override the usual backup suffix | 覆蓋通常備份後綴 | |
| -t, --target-directory=DIRECTORY | copy all SOURCE arguments into DIRECTORY | 把所有 SOURCE 自變量拷貝到 DIRECTORY | |
| -T, --no-target-directory | treat DEST as a normal file | 把 DEST 視為普通文件 | |
| -u, --update |
copy only when the SOURCE file is newer than the destination file or when the destination file is missing |
僅當 SOURCE 文件比目的地文件更新時纔拷貝 或當目的地文件丟失時 |
|
| -v, --verbose | explain what is being done | 解釋正在做什麼 | |
| -x, --one-file-system | stay on this file system | 保留此文件係統 | |
| -Z | set SELinux security context of destination file to default type | 把目的地文件的 SELinux 安全上下文設為默認類型 | |
| --context[=CTX] | like -Z, or if CTX is specified then set the SELinux or SMACK security context to CTX | 類似 -Z,或若 CTX 被指定,則把 SELinux 或 SMACK 安全上下文設為 CTX | |
| --help | display this help and exit | 展示幫助並退齣 | |
| --version | output version information and exit | 輸齣版本信息並退齣 |
默認情況下,通過粗略試探檢測稀疏 SOURCE 文件, 且相應 DEST 文件也會變得稀疏。 這是通過 --sparse=auto 的選擇行為。
指定 --sparse=always 能創建稀疏 DEST 文件, 每當 SOURCE 文件包含足夠長的零字節序列。
使用 --sparse=never 能禁止稀疏文件的創建。
當 --reflink[=always] 被指定時, 履行輕量級拷貝 (僅在修改時纔拷貝數據塊)。
若這不可能,則拷貝失敗, 或若 --reflink=auto 被指定,則迴退到標準拷貝。
備份後綴為 ~,除非采用 --suffix 或 SIMPLE_BACKUP_SUFFIX 設置。
可通過 --backup 選項或透過 VERSION_CONTROL 環境變量,選擇版本控製方法。 下麵是值:
| 參數 | EN 解釋 | 中文翻譯 | 備注 |
|---|---|---|---|
| none, off | never make backups (even if --backup is given) | 從不進行備份 (即使 --backup 被給齣) | |
| numbered, t | make numbered backups | 進行編號備份 | |
| existing, nil | numbered if numbered backups exist, simple otherwise | 編號,若存在編號備份;否則,simple | |
| simple, never | always make simple backups | 總是進行簡單的備份 |
作為特殊情況, 當 force 和 backup 選項被給定且 SOURCE 和 DEST 與現有常規文件的名稱相同時, cp 會對 SOURCE 進行備份。
| 功能 | 命令 | 文字解釋 | 示例 | 示例解釋 |
|---|---|---|---|---|
| 幫助 | cp --help | 展示幫助信息 | ||
| 版本 | cp --version | 展示版本信息 |
版權聲明: 本文為獨傢原創稿件,版權歸 樂數軟件 ,未經許可不得轉載。