Linux 文件管理-基础知识-文件拷贝-【cp】复制文件

cp = copy 

需要了解的基础知识

拷贝一个文件,文件的权限,文件的属主|属组,文件的大小,文件的位置,文件的内容,文件的硬链接,文件的inode会如何变化?

Linux下的文件都有哪些信息组成?

Linix下通过什么工具去查看一个信息?

 

CP命令操作手册翻译版

 

参数长参数类型释义
 -a--archive 此选项通常在复制目录时使用,它保留链接、文件属性,并复制目录下的所有内容。其作用等于dpR参数组合
 --attributes-only 只拷贝属性,不拷贝内容,文件的size,属主,属组,权限会因环境上下文而改变
 --backup=backupmodel[simple,t|numbered,never] 备份文件,simple模式会删除前一次存储的备份,新建一个全新的备份文件,t|numbered 如果第一次备份会为备份名,第二次备份会在末尾先增加~,大于第二次的备份名后缀为增加~N-2~
-b  等同于cp --backup=t
 --copy-contents  
-d  复制时保留链接。即软连接依然会被拷贝为一个软连接
-f--force 覆盖已经存在的目标文件而不给出提示
 -i--interactive(互动,交互式的) 与-f选项相反,在覆盖目标文件之前给出提示,要求用户确认是否覆盖,回答"y"时目标文件将被覆盖
-H   
-l--link 不复制文件,只是生成链接文件,建立硬链接
 -L--dereference  
 -n--no-clobber 不要覆盖已存在的文件
-P--no-dereference  
-p    除复制文件的内容外,还把修改时间和访问权限也复制到新文件中
 --preserve[=ATTR_LIST]  
 -c  已过期   
 --no-preserve=ATTR_LIST  
  --parents 复制前在目标目录创建来源文件路径中的所有目录
-R, -r--recursive 若给出的源文件是一个目录文件,此时将复制该目录下所有的子目录和文件
 --reflink[=WHEN]  
 --remove-destination 尝试打开目标文件前先删除已存在的目的地 文件 (等同于 --force 选项)
 --sparse=WHEN  
 --strip-trailing-slashes 删除参数中所有源文件/目录末端的斜杠
 -s--symbolic-link 拷贝一个文件时,无论这个文件时源文件,还是软连接都会被拷贝为一个软连接
 -S--suffix=SUFFIX 自定义文件备份的后缀
-t--target-directory=DIRECTORY 把选中的文件copy到该目录中,格式:copy -t target_dir file_1 file_n
-T--no-target-directory  
-u--update  
 -v--verbose 显示命令执行的详细信息
-x--one-file-system  

CP 命令操作手册原文版

CP(1)                                                       User Commands                                                      CP(1)

NAME
       cp - copy files and directories

SYNOPSIS
       cp [OPTION]... [-T] SOURCE DEST
       cp [OPTION]... SOURCE... DIRECTORY
       cp [OPTION]... -t DIRECTORY SOURCE...

DESCRIPTION
       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 -dR --preserve=all

       --attributes-only
              don't copy the file data, just the attributes

       --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=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
              do not overwrite an existing file (overrides a previous -i option)

       -P, --no-dereference
              never follow symbolic links in SOURCE

       -p     same as --preserve=mode,ownership,timestamps

       --preserve[=ATTR_LIST]
              preserve the specified attributes (default: mode,ownership,timestamps), if possible  additional  attributes:  context,
              links, xattr, all

       -c     deprecated, 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

       --reflink[=WHEN]
              control clone/CoW copies. See below

       --remove-destination
              remove each existing destination file before attempting to open it (contrast with --force)

       --sparse=WHEN
              control creation of sparse files. See below

       --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

       -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 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

       -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 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.

       When  --reflink[=always]  is  specified, perform a lightweight copy, where the data blocks are copied only when modified.  If
       this is not possible the copy fails, or if --reflink=auto is specified, fall back to a standard copy.

       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.

       GNU coreutils online help: <http://www.gnu.org/software/coreutils/> Report cp  translation  bugs  to  <http://translationpro‐
       ject.org/team/>
 Manual page cp(1) line 87 (press h for help or q to quit)

CP命令操作实践

cp -a 【完全拷贝文件|目录(递归)除Inode的所有属性】

此选项通常在复制目录时使用,它保留链接、文件属性,并复制目录下的所有内容。其作用等于dpR参数组合

cp -f 强制覆盖已存在的文件

cp --attributes-only 只拷贝属性[权限,属组,属主受限于上下文]

cp --backup 备份文件【权限属组和属组受限于拷贝的上下文】

cp -b 等同于cp --backup=t

copy -l 复制文件生产硬链接

copy -s 拷贝文件为软连接

copy -S 自定义文件备份的后缀

copy -t copy 文件到指定目录

命令格式:copy -t target_dir file_1 file_n

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值