免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2548 | 回复: 0
打印 上一主题 下一主题

cp ——linux拷贝命令 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-03-23 11:19 |只看该作者 |倒序浏览

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

               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/93926/showart_1873905.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP