linux命令学习总结:cp命令
    

cp命令用来复制文件或目录。指令英文原义:copy

指令所在路径:/bin/cp

命令语法:

usage: cp [option]... [-t] source dest

or: cp [option]... source... directory

or: cp [option]... -t directory source...

命令参数:

此命令参数是red hat enterprise linux server release 5.7下cp命令参数,不同版本linux的cp命令参数有可能不同。

参数

长参数

描叙

-a

等同于-dr

-b

若删除或者覆盖目标文件,将对目标文件进行备份,备份文件以备份的字符串结尾

-d

复制符号链接

-f

强制复制

-h

强制cp命令复制符号链接。缺省值是跟随符号链接,也就是将文件复制到符号链接指向处。

-i

交互式模式。覆盖目标文件之前先要进行询问

-l

建立硬链接,而非复制

-p

源目录或者文件的属性保留

-p

源目录或者文件的路劲保留

-r/-r

处理指定目录以及子目录

-v

--verbose

显示命令执行的详细信息

--help

显示命令在线帮助

--version

显示命令版本信息

使用示例:

1: 查看rmdir命令的帮助信息

[root@db-server ~]# cp --helpusage: cp [option]... [-t] source destor: cp [option]... source... directoryor: cp [option]... -t directory source...copy source to dest, or multiple source(s) to directory.mandatory arguments to long options are mandatoryforshort options too.-a, --archive same as -dr --preserve=all--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-f, --forceifan existing destination file cannot beopened, 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, --no-dereference never follow symbolic links-p same as --preserve=mode,ownership,timestamps--preserve[=attr_list] preserve the specified attributes (default:mode,ownership,timestamps),ifpossibleadditional attributes: context, links,xattr, all-c same as --preserve=context--no-preserve=attr_list don't preserve the specified attributes--parents use full source file name under directory-r, -r, --recursive copy directories recursively--remove-destination remove each existing destination file beforeattempting to open it (contrast with --force)--sparse=when control creation of sparse files--strip-trailing-slashes remove any trailing slashes from each sourceargument-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-t, --no-target-directory treat dest as a normal file-u, --update copy only when the source file is newerthan the destination file or when thedestination file is missing-v, --verbose explain what is being done-x, --one-file-system stay on this file system-z, --context=context set security context of copy to context--help display this help and exit--version output version information and exitby default, sparse source files are detected by a crude heuristic and thecorresponding dest file is made sparse as well. that is the behaviorselected by --sparse=auto. specify --sparse=always to create a sparse destfile 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 throughthe version_control environment variable. here are the values:none, off never make backups (evenif--backup is given)numbered, t make numbered backupsexisting, nil numberedifnumbered backups exist, simple otherwisesimple, never always make simple backupsas a special case, cp makes a backup of source when the force and backupoptions are given and source and dest are the same nameforan existing,regular file.report bugs tobug-coreutils@gnu.org.

[root@db-server ~]# man cp

2: 拷贝文件file1并更名为file2

[root@db-server kerry]# lsfile1[root@db-server kerry]# cp file1 file2[root@db-server kerry]# lsfile1 file2[root@db-server kerry]#

3:拷贝kerry目录下文件到tmp目录下

[root@db-server ~]# cp /home/kerry/* /tmp[root@db-server ~]# cd /tmp

4:将目录下的所有目录包括子目录陆续复制到另外一个目录

[root@db-server ~]#cp -r /home/tomcat/ /tmp/bak

5: 复制时保留文件属性(保存与源文件相关联的修改日期、时间和访问控制列表等)

[root@db-server kerry]# ls -lrttotal 8-rw-r--r-- 1 root root 3886 jan 19 23:04 install.log.syslog[root@db-server kerry]# cp -p install.log.syslog install.log.syslog.bak1[root@db-server kerry]# cp install.log.syslog install.log.syslog.bak2[root@db-server kerry]# ls -lrttotal 24-rw-r--r-- 1 root root 3886 jan 19 23:04 install.log.syslog.bak1-rw-r--r-- 1 root root 3886 jan 19 23:04 install.log.syslog-rw-r--r-- 1 root root 3886 jan 19 23:10 install.log.syslog.bak2

6: 以交换形式拷贝文件

[root@db-server kerry]# cp -i /var/log/* ./cp: overwrite `./acpid'? ncp: overwrite `./anaconda.log'? ncp: overwrite `./anaconda.syslog'? ycp: overwrite `./anaconda.xlog'? ncp: omitting directory `/var/log/audit'cp: overwrite `./boot.log'? ncp: overwrite `./boot.log.1'? ncp: overwrite `./boot.log.2'? n

相关阅读
  • 关于Linux历史命令相关用法总结
  • linux学习总结
  • Linux服务器的查看系统信息命令总
  • Linux中cp 命令COPY文件不提示而直
  • Linux学习
  • Linux驱动总结3
  • linux命令
  • linux命令的获得帮助
  • Linux 基础学习Shell 编程基础
  • 【程序】嵌入式linux学习步骤
  • linux命令的操作命令
  • linux常用命令有哪些?linux命令大
  • 基础:怎样使用Linux磁盘分区的命
  • 常用Linux命令
  • Linux学习的路线图概要介绍
  • linux命令文件数
  • Linux查看命令
  • Linux chmod 命令
  • Linux基础知识:用Linux命令创建快
  • linux apache启动命令
  • Linux修改密码的命令
  •  



     
     
         

    收录时间:2016年11月12日 17:04:44 来源:未知 作者:匿名
    上一篇:区别common, ordinary, usual 和 normal  (电脑版  手机版)
     
    创建分享人
    合昏尚知时
    最新问题
     
    喜欢此文章的还喜欢
    Copyright by www.chinabaike.com;All rights reserved. 联系:QQ:469681782