做这样一个测试,文件夹a里面包含一个符号连接,我们用cp的不同参数来测试看看效果
-bash-3.00$ uname -a
sunos sunv480 5.10 generic_127127-11 sun4u sparc sunw,sun-fire-480r
-bash-3.00$ ls -lr a
a:
total 2
lrwxrwxrwx 1 oracle10 dba 9 aug 5 16:59 ftp1.sh -> ../ftp.sh
-bash-3.00$ rm -rf b
-bash-3.00$ cp -r a b
-bash-3.00$ ls -lr b
b:
total 2
-rw-r--r-- 1 oracle10 dba 239 aug 5 17:04 ftp1.sh
-bash-3.00$ rm -r b
-bash-3.00$ cp -rh a b
cp: illegal option -- h
usage: cp [-f] [-i] [-p] [-@] f1 f2
cp [-f] [-i] [-p] [-@] f1 ... fn d1
cp -r|-r [-h|-l|-p] [-f] [-i] [-p] [-@] d1 ... dn-1 dn
-bash-3.00$ cp -rh a b
-bash-3.00$ ls -lr b
b:
total 2
lrwxrwxrwx 1 oracle10 dba 9 aug 5 17:05 ftp1.sh -> ../ftp.sh
-h takes actions based on the type and contents of the
file referenced by any symbolic link specified as a
source_file operand.
if the source_file operand is a symbolic link, then cp
copies the file referenced by the symbolic link for
the source_file operand. all other symbolic links
encountered during traversal of a file hierarchy are
preserved.
[oracle@asm tmp]$ uname -a
linux asm 2.6.9-22.el #1 mon sep 19 18:20:28 edt 2005 i686 i686 i386 gnu/linux
[oracle@asm tmp]$ ls -lr a
a:
total 0
lrwxrwxrwx 1 oracle oinstall 4 aug 5 08:45 f1 -> ../f
[oracle@asm tmp]$ rm -rf b
[oracle@asm tmp]$ cp -r a b
[oracle@asm tmp]$ ls -lr b
b:
total 0
lrwxrwxrwx 1 oracle oinstall 4 aug 5 08:48 f1 -> ../f
[oracle@asm tmp]$ rm -rf b
[oracle@asm tmp]$ cp -rh a b
cp: invalid option -- h
try `cp --help' for more information.
[oracle@asm tmp]$ cp -rh a b
[oracle@asm tmp]$ ls -lr b
b:
total 0
lrwxrwxrwx 1 oracle oinstall 4 aug 5 08:48 f1 -> ../f
-h follow command-line symbolic links
$ ls -lr a
total 0
lrwxrwxrwx 1 shangj dba 9 aug 5 17:08 ftp1.sh -> ../ftp.sh
$ cp -r a b
$ ls -lr b
total 0
lrwxrwxrwx 1 shangj dba 9 aug 5 17:09 ftp1.sh -> ../ftp.sh
$ rm -r b
$ cp -rh a b
cp: illegal option -- h
usage: cp [-f|-i] [-p] [-s] [-e warn|force|ignore] source_file target_file
cp [-f|-i] [-p] [-s] [-e warn|force|ignore] source_file ... target_directory
cp [-f|-i] [-p] [-s] -r|-r [-e warn|force|ignore] source_directory ... target_directory
$ cp -rh a b
cp: illegal option -- h
usage: cp [-f|-i] [-p] [-s] [-e warn|force|ignore] source_file target_file
cp [-f|-i] [-p] [-s] [-e warn|force|ignore] source_file ... target_directory
cp [-f|-i] [-p] [-s] -r|-r [-e warn|force|ignore] source_directory ... target_directory
$ uname -a
hp-ux j5000 b.11.11 u 9000/785 2007065683 unlimited-user license
p270$(/home/shangj/ganhk)ls -lr a
total 0
lrwxrwxrwx 1 shangj rd 9 aug 05 17:05 ftp1.sh -> ../ftp.sh
p270$(/home/shangj/ganhk)cp -r a b
p270$(/home/shangj/ganhk)ls -lr b
total 1
-rw-r--r-- 1 shangj rd 239 aug 05 17:06 ftp1.sh
p270$(/home/shangj/ganhk)rm -rf b
p270$(/home/shangj/ganhk)cp -rh a b
p270$(/home/shangj/ganhk)ls -lr b
total 0
lrwxrwxrwx 1 shangj rd 9 aug 05 17:06 ftp1.sh -> ../ftp.sh
p270$(/home/shangj/ganhk)rm -rf b
p270$(/home/shangj/ganhk)cp -rh a b
p270$(/home/shangj/ganhk)ls -lr b
total 0
lrwxrwxrwx 1 shangj rd 9 aug 05 17:06 ftp1.sh -> ../ftp.sh
p270$(/home/shangj/ganhk)uname -a
aix p270 2 5 0005a9dc4c00
-h forces the cp command to copy symbolic links. the default is to follow
symbolic links, that is, to copy files to which symbolic links point.
-h take actions based on the type and contents of the file referenced by any
symbolic link specified as a sourcefile operand.
最后小节以下:
1>. linux/hpux基本一致,默认连接还是连接,但hpux不支持h/h参数
2>. sunos/aix默认连接就直接复制文件了,sunos如果连接还是连接就需要用h参数了,aix可以用h/h。
但没有明白aix的h, h区别。
阅读(11338) | 评论(0) | 转发(0) |