文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>cp复制符号连接的问题

cp复制符号连接的问题

时间:2010-08-05  来源:g_hk

做这样一个测试,文件夹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区别。

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载