用法:cp [选项]... [-T] 源文件 目标文件
或:cp [选项]... 源文件... 目录
或:cp [选项]... -t 目录 源文件...
Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.
必选参数对长短选项同时适用。
-a, --archive 等于-dR --preserve=all
--attributes-only 仅复制属性而不复制数据 --backup[=CONTROL 为每个已存在的目标文件创建备份
-b 类似--backup 但不接受参数
--copy-contents 在递归处理是复制特殊文件内容
-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 选项失效)
-P, --no-dereference 不跟随源文件中的符号链接
-p 等于--preserve=模式,所有权,时间戳
--preserve[=属性列表 保持指定的属性(默认:模式,所有权,时间戳),如果
可能保持附加属性:环境、链接、xattr 等
--sno-preserve=属性列表 不保留指定的文件属性
--parents 复制前在目标目录创建来源文件路径中的所有目录
-R, -r, --recursive 递归复制目录及其子目录内的所有内容
--reflink[=WHEN] 控制克隆/CoW 副本。请查看下面的内如。
--remove-destination 尝试打开目标文件前先删除已存在的目的地
文件 (相对于 --force 选项)
--sparse=WHEN 控制创建稀疏文件的方式
--strip-trailing-slashes 删除参数中所有源文件/目录末端的斜杠
-s, --symbolic-link 只创建符号链接而不复制文件
-S, --suffix=后缀 自行指定备份文件的后缀
-t, --target-directory=目录 将所有参数指定的源文件/目录
复制至目标目录
-T, --no-target-directory 将目标目录视作普通文件
-u, --update 只在源文件比目标文件新,或目标文件
不存在时才进行复制
-v, --verbose 显示详细的进行步骤
-x, --one-file-system 不跨越文件系统进行操作
-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 显示版本信息并退出
默认情况下,源文件的稀疏性仅仅通过简单的方法判断,对应的目标文件目标文件也
被为稀疏。这是因为默认情况下使用了--sparse=auto 参数。如果明确使用
--sparse=always 参数则不论源文件是否包含足够长的0 序列也将目标文件创文
建为稀疏件。
使用--sparse=never 参数禁止创建稀疏文件。
当指定了--reflink[=always] 参数时执行轻量化的复制,即只在数据块被修改的
情况下才复制。如果复制失败或者同时指定了--reflink=auto,则返回标准复制模式。
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 不进行备份(即使使用了--backup 选项)
numbered, t 备份文件加上数字进行排序
existing, nil 若有数字的备份文件已经存在则使用数字,否则使用普通方式备份
simple, never 永远使用普通方式备份
有一个特别情况:如果同时指定--force 和--backup 选项,而源文件和目标文件
是同一个已存在的一般文件的话,cp 会将源文件备份。
GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
请向<http://translationproject.org/team/zh_CN.html> 报告cp 的翻译错误
Full documentation at: <http://www.gnu.org/software/coreutils/cp>
or available locally via: info '(coreutils) cp invocation'
或:cp [选项]... 源文件... 目录
或:cp [选项]... -t 目录 源文件...
Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.
必选参数对长短选项同时适用。
-a, --archive 等于-dR --preserve=all
--attributes-only 仅复制属性而不复制数据 --backup[=CONTROL 为每个已存在的目标文件创建备份
-b 类似--backup 但不接受参数
--copy-contents 在递归处理是复制特殊文件内容
-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 选项失效)
-P, --no-dereference 不跟随源文件中的符号链接
-p 等于--preserve=模式,所有权,时间戳
--preserve[=属性列表 保持指定的属性(默认:模式,所有权,时间戳),如果
可能保持附加属性:环境、链接、xattr 等
--sno-preserve=属性列表 不保留指定的文件属性
--parents 复制前在目标目录创建来源文件路径中的所有目录
-R, -r, --recursive 递归复制目录及其子目录内的所有内容
--reflink[=WHEN] 控制克隆/CoW 副本。请查看下面的内如。
--remove-destination 尝试打开目标文件前先删除已存在的目的地
文件 (相对于 --force 选项)
--sparse=WHEN 控制创建稀疏文件的方式
--strip-trailing-slashes 删除参数中所有源文件/目录末端的斜杠
-s, --symbolic-link 只创建符号链接而不复制文件
-S, --suffix=后缀 自行指定备份文件的后缀
-t, --target-directory=目录 将所有参数指定的源文件/目录
复制至目标目录
-T, --no-target-directory 将目标目录视作普通文件
-u, --update 只在源文件比目标文件新,或目标文件
不存在时才进行复制
-v, --verbose 显示详细的进行步骤
-x, --one-file-system 不跨越文件系统进行操作
-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 显示版本信息并退出
默认情况下,源文件的稀疏性仅仅通过简单的方法判断,对应的目标文件目标文件也
被为稀疏。这是因为默认情况下使用了--sparse=auto 参数。如果明确使用
--sparse=always 参数则不论源文件是否包含足够长的0 序列也将目标文件创文
建为稀疏件。
使用--sparse=never 参数禁止创建稀疏文件。
当指定了--reflink[=always] 参数时执行轻量化的复制,即只在数据块被修改的
情况下才复制。如果复制失败或者同时指定了--reflink=auto,则返回标准复制模式。
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 不进行备份(即使使用了--backup 选项)
numbered, t 备份文件加上数字进行排序
existing, nil 若有数字的备份文件已经存在则使用数字,否则使用普通方式备份
simple, never 永远使用普通方式备份
有一个特别情况:如果同时指定--force 和--backup 选项,而源文件和目标文件
是同一个已存在的一般文件的话,cp 会将源文件备份。
GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
请向<http://translationproject.org/team/zh_CN.html> 报告cp 的翻译错误
Full documentation at: <http://www.gnu.org/software/coreutils/cp>
or available locally via: info '(coreutils) cp invocation'
Ubuntu中复制文件或目录的命令
cp(copy)命令
该命令的功能是将给出的文件或目录拷贝到另一文件或目录中。
语法: cp [选项] 源文件或目录 目标文件或目录
说明:该命令把指定的源文件复制到目标文件或把多个源文件复制到目标目录中。
该命令的各选项含义如下:
- a 该选项通常在拷贝目录时使用。它保留链接、文件属性,并递归地拷贝目录,其作用等于dpR选项的组合。
- d 拷贝时保留链接。
- f 删除已经存在的目标文件而不提示。
- i 和f选项相反,在覆盖目标文件之前将给出提示要求用户确认。回答y时目标文件将被覆盖,是交互式拷贝。
- p 此时cp除复制源文件的内容外,还将把其修改时间和访问权限也复制到新文件中。
- r 若给出的源文件是一目录文件,此时cp将递归复制该目录下所有的子目录和文件。此时目标文件必须为一个目录名。
- l 不作拷贝,只是链接文件。
需要说明的是,为防止用户在不经意的情况下用cp命令破坏另一个文件,如用户指定的目标文件名已存在,用cp命令拷贝文件后,这个文件就会被新源文件覆盖,因此,建议用户在使用cp命令拷贝文件时,最好使用i选项。
例如:将/home/wally/test中 test.c 的文件复制到/local/arm 中,命令为:
cd /wally/test
ls
sudo cp -i test.c /local/arm