- 论坛徽章:
- 0
|
cp
作用:
将文件复制至,或将多个复制至。
用法:cp [选项]... [-T] 源 目的
或:cp [选项]... 源... 目录
或:cp [选项]... -t 目录 源...
注:长选项必须用的参数在使用短选项时也是必须的。
选项说明:
-a, --archive 等于 -dpR
--backup[=CONTROL] 为每个已存在的目的地文件创建备份文件
CONTROL的取值如下:
none, off 不会进行备份 (即使使用了 --backup 选项)
numbered, t 备份文件会加上数字
existing, nil 若有数字的备份文件已经存在则使用数字,否则使用普通方式备份
simple, never 永远使用普通方式备份
[root@localhost Desktop]# cp --backup=off fds fuck
[root@localhost Desktop]# cp --backup=numbered fds fuck
[root@localhost Desktop]# cp --backup=simple fds fuck
[root@localhost Desktop]# cp --backup=existing fds fuck
原来文件列表:
fds fds~ fuck madline madline~ MySQL-server-5.0.18-0.i386.rpm pikview-0.9.1.tar.gz second second~ teff 新文件~
效果依次如下:
fds fds~ fuck madline madline~ MySQL-server-5.0.18-0.i386.rpm pikview-0.9.1.tar.gz second second~ teff 新文件~(没有任何改变)
fds fds~ fuck fuck.~1~ madline madline~ MySQL-server-5.0.18-0.i386.rpm pikview-0.9.1.tar.gz second second~ teff 新文件~(增加了文件:fuck.~1~)
fds fuck fuck.~1~ madline~ pikview-0.9.1.tar.gz second~ 新文件~ fds~ fuck~ madline MySQL-server-5.0.18-0.i386.rpm second teff(又增加了文件fuck~)
fds fuck fuck.~1~ madline MySQL-server-5.0.18-0.i386.rpm second teff
fds~ fuck~ fuck.~2~ madline~ pikview-0.9.1.tar.gz second~ 新文件~
(因为已经数字备份过,所以继续用数字备份方式,增加了文件funck.~2~)
-b 类似 --backup,但不接受任何参数
--copy-contents 当使用递归模式时复制特殊文件的内容(???不明白???)
-d 等于 --no-dereference --preserve=link
-f, --force 如果目的地址文件已经存在并且不能打开,则删除,并再试一次。
-i, --interactive 覆盖时该出提示先。(默认如此)
-H follow command-line symbolic links
-l, --link 链接文件而不复制
-L, --dereference 总是跟随符号链接(如何理解??不明白??)
[root@localhost Desktop]# cp -L fuck fuck5
-rw-r--r-- 3 root root 7502 11-24 13:15 fuck
-rw-r--r-- 1 root root 7502 11-26 09:02 fuck5
-P, --no-dereference 从不跟随符号链接(??不明白???)
[root@localhost Desktop]# cp -p fuck fuck5(和上面的例子作一个对比!!!!!)
-rw-r--r-- 3 root root 7502 11-24 13:15 fuck
-rw-r--r-- 1 root root 7502 11-24 13:15 fuck5
从两个例子的对比可以看出,这两个命令的区别在于一个复制了修改时间,而另外一个没有。可能还有更多不同,但是暂时尚未发觉。
-p same as --preserve=mode,ownership,timestamps
--preserve[=ATTR_LIST] preserve the specified attributes (default:
mode,ownership,timestamps), if possible
additional attributes: links, 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 复制目录及目录内的所有项目
--remove-destination 尝试打开目的地文件前先删除已存在的目的地
文件 (与 --force 选项作对比)
--sparse=WHEN control creation of sparse files
--strip-trailing-slashes remove any trailing slashes from each SOURCE
argument
-s, --symbolic-link 添加符号链接而不是复制文件
-S, --suffix=SUFFIX 重写常用的备份方式
-t, --target-directory=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, --c set security context of copy to CONTEXT
--help 显示此帮助信息并退出
--version 输出版本信息并退
===========================================================================
默认使用模式中,文件是否 sparse 文件会由一种粗略的方式决定,而且相应
的文件也会是 sparse 文件。此方式等于使用 --sparse=auto 选项。指定
--sparse=always 则只要文件含有足够长的 0 字节都会产生 sparse 的
文件。
使用 --sparse=never 会禁止产生 sparse 文件。
备份文件的后缀为“~”,除非以 --suffix 选项或是 SIMPLE_BACKUP_SUFFIX
环境变量指定。版本控制的方式可透过 --backup 选项或 VERSION_CONTROL 环境
变量来选择。以下是可用的变量值:
none, off 不会进行备份 (即使使用了 --backup 选项)
numbered, t 备份文件会加上数字
existing, nil 若有数字的备份文件已经存在则使用数字,否则使用普通方式备份
simple, never 永远使用普通方式备份
有一个特别情况:如果同时指定 --force 和 --backup 选项,而且和
是同一个已存在的一般文件的话,cp 会将文件备份。
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/4775/showart_419165.html |
|