cp(copy)
cp(copy)功能说明:复制文件或目录。
语 法:cp [-abdfilpPrRsuvx][-S <备份字尾字符串>][-V <备份方式>][--help][--spares=<使用时机>][--version][源文件或目录][目标文件或目录] [目的目录]
补充说明:cp指令用在复制文件或目录,如同时指定两个以上的文件或目录,且最后的目的地是一个已经存在的目录,则它会把前面指定的所有文件或目录复制到该目录中。若同时指定多个文件或目录,而最后的目的地并非是一个已存在的目录,则会出现错误信息。
参 数:
-a或--archive 此参数的效果和同时指定"-dpR"参数相同。
-b或--backup 删除,覆盖目标文件之前的备份,备份文件会在字尾加上一个备份字符串。
-d或--no-dereference 当复制符号连接时,把目标文件或目录也建立为符号连接,并指向与源文件或目录连接的原始文件或目录。
-f或--force 强行复制文件或目录,不论目标文件或目录是否已存在。
-i或--interactive 覆盖既有文件之前先询问用户。
-l或--link 对源文件建立硬连接,而非复制文件。
-p或--preserve 保留源文件或目录的属性。
-P或--parents 保留源文件或目录的路径。
-r 递归处理,将指定目录下的文件与子目录一并处理。
-R或--recursive 递归处理,将指定目录下的所有文件与子目录一并处理。
-s或--symbolic-link 对源文件建立符号连接,而非复制文件。
-S<备份字尾字符串>或--suffix=<备份字尾字符串> 用"-b"参数备份目标文件后,备份文件的字尾会被加上一个备份字符串,预设的备份字尾字符串是符号"~"。
-u或--update 使用这项参数后只会在源文件的更改时间较目标文件更新时或是 名称相互对应的目标文件并不存在,才复制文件。
-v或--verbose 显示指令执行过程。
-V<备份方式>或--version-control=<备份方式> 用"-b"参数备份目标文件后,备份文件的字尾会被加上一个备份字符串,这字符串不仅可用"-S"参数变更,当使用"-V"参数指定不同备份方式时,也会产生不同字尾的备份字串。
-x或--one-file-system 复制的文件或目录存放的文件系统,必须与cp指令执行时所处的文件系统相同,否则不予复制。
--help 在线帮助。
--sparse=<使用时机> 设置保存稀疏文件的时机。
--version 显示版本信息。
cp
cp [options] file1 file2 cp [options] files directory
Copy file1 to file2, or copy one or more files to the same names under directory. If the destination is an existing file, the file is overwritten; if the destination is an existing directory, the file is copied into the directory (the directory is not overwritten).
Options
Preserve attributes of original files where possible. The same as -dpr.
Back up files that would otherwise be overwritten.
Do not dereference symbolic links; preserve hard-link relationships between source and copy.
Remove existing files in the destination.
Prompt before overwriting destination files. On most systems, this flag is turned off by default except for the root user, who is normally prompted before overwriting files.
Make hard links, not copies, of nondirectories.
Preserve all information, including owner, group, permissions, and timestamps.
Preserve intermediate directories in source. The last argument must be the name of an existing directory. For example, the command:
cp --parents jphekman/book/ch1 newdir
copies the file jphekman/book/ch1 to the file newdir/jphekman/book/ch1, creating intermediate directories as necessary.
Copy directories recursively.
Set suffix to be appended to backup files. This may also be set with the SIMPLE_BACKUP_SUFFIX environment variable. The default is ~. You need to explicitly include a period if you want one before the suffix (for example, specify .bak, not bak).
Make symbolic links instead of copying. Source filenames must be absolute.
Handle files that have "holes" (are defined as a certain size but have less data). always creates a sparse file, auto creates one if the input file is sparse, and never creates a non-sparse file without holes.
Do not copy a file to an existing destination with the same or newer modification time.
Before copying, print the name of each file.
Set the type of backups made. You may also use the VERSION_CONTROL environment variable. The default is existing. Valid arguments are:
t, numbered Always make numbered backups.
nil, existing Make numbered backups of files that already have them; otherwise, make simple backups.
never, simple Always make simple backups.
-x, --one-file-system Ignore subdirectories on other filesystems.
Example
Copy the contents of the guest directory recursively into the /archives/guest/ directory, and display a message for each file copied:
cd /archives && cp -av /home/guest guest