Chinaunix首页 | 论坛 | 博客
  • 博客访问: 10730045
  • 博文数量: 2905
  • 博客积分: 20098
  • 博客等级: 上将
  • 技术积分: 36298
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-23 05:00
文章存档

2012年(1)

2011年(3)

2009年(2901)

分类: LINUX

2009-03-23 11:19:00

该命令的功能是将给出的文件或目录拷贝到另一文件或目录中,同MSDOS下的copy命令一样,功能十分强大。
语法: cp [选项] 源文件或目录 目标文件或目录
说明:该命令把指定的源文件复制到目标文件或把多个源文件复制到目标目录中。
该命令的各选项含义如下:
- a 该选项通常在拷贝目录时使用。它保留链接、文件属性,并递归地拷贝目录,其作用等于dpR选项的组合。
- d 拷贝时保留链接。
- f 删除已经存在的目标文件而不提示。
- i 和f选项相反,在覆盖目标文件之前将给出提示要求用户确认。回答y时目标文件将被覆盖,是交互式拷贝。
- p 此时cp除复制源文件的内容外,还将把其修改时间和访问权限也复制到新文件中。
- r 若给出的源文件是一目录文件,此时cp将递归复制该目录下所有的子目录和文件。此时目标文件必须为一个目录名。
- l 不作拷贝,只是链接文件。

举例:
将文件abc复制(已存在),并命名为123:
     cp abc 123
将所有的C语言程序拷贝到temp子目录中:
    cp *.c temp

[dennischen@lxw12 temp]$ cp --help
Usage: cp [OPTION]... SOURCE DEST
or: cp [OPTION]... SOURCE... DIRECTORY
or: cp [OPTION]... --target-directory=DIRECTORY SOURCE...
Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.

Mandatory arguments to long options are mandatory for short options too.
-a, --archive                same as -dpR
      --backup[=CONTROL]       make a backup of each existing destination file
-b                           like --backup but does not accept an argument
      --copy-contents          copy contents of special files when recursive
-d                           same as --no-dereference --preserve=link
      --no-dereference         never follow symbolic links
-f, --force                  if an existing destination file cannot be
                                 opened, remove it and try again
-i, --interactive            prompt before overwrite
-H                           follow command-line symbolic links
-l, --link                   link files instead of copying
-L, --dereference            always follow symbolic links
-p                           same as --preserve=mode,ownership,timestamps
      --preserve[=ATTR_LIST]   preserve the specified attributes (default:
                                 mode,ownership,timestamps), if possible
                                 additional attributes: links, all
      --no-preserve=ATTR_LIST don't preserve the specified attributes
      --parents                append source path to DIRECTORY
-P                           same as `--no-dereference'
-R, -r, --recursive          copy directories recursively
      --remove-destination     remove each existing destination file before
                                 attempting to open it (contrast with --force)
      --reply={yes,no,query}   specify how to handle the prompt about an
                                 existing destination file
      --sparse=WHEN            control creation of sparse files
      --strip-trailing-slashes remove any trailing slashes from each SOURCE
                                 argument
-s, --symbolic-link          make symbolic links instead of copying
-S, --suffix=SUFFIX          override the usual backup suffix
      --target-directory=DIRECTORY move all SOURCE arguments into DIRECTORY
-u, --update                 copy only when the SOURCE file is newer
                                 than the destination file or when the
                                 destination file is missing
-v, --verbose                explain what is being done
-x, --one-file-system        stay on this file system
      --help     display this help and exit
      --version output version information and exit

By default, sparse SOURCE files are detected by a crude heuristic and the
corresponding DEST file is made sparse as well. That is the behavior
selected by --sparse=auto. Specify --sparse=always to create a sparse DEST
file whenever the SOURCE file contains a long enough sequence of zero bytes.
Use --sparse=never to inhibit creation of sparse files.

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       never make backups (even if --backup is given)
numbered, t     make numbered backups
existing, nil   numbered if numbered backups exist, simple otherwise
simple, never   always make simple backups

As a special case, cp makes a backup of SOURCE when the force and backup
options are given and SOURCE and DEST are the same name for an existing,
regular file.

Report bugs to <>.
[dennischen@lxw12 temp]$

 
阅读(1719) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~