修改符号链接的属主的方法 (Linux/Unix)
发布于 2008-01-15 18:49 阅读:141,296 评论:0 标签: Linux 方法 链接

    如下,检查为FreeBSD 4.8p-STABLE

以下是引用片段:
autoinstall# uname -a
FreeBSD autoinstall 4.8p-STABLE FreeBSD 4.8p-STABLE #0: Sun Nov  9 04:39:25 GMT 2003     root@dell1550.sina.com.cn:/usr/obj/usr/src/sys/SINA  i386

    我当前为root

以下是引用片段:
autoinstall# whoami
root

    建立一个文件

以下是引用片段:
autoinstall# touch a

autoinstall# ls -l
-rw-r--r--  1 root       wheel    0 Jan 15 17:38 a

    建立一个软连接:

以下是引用片段:
autoinstall# ln -s a b
autoinstall#
autoinstall# ls -l
-rw-r--r--  1 root       wheel    0 Jan 15 17:38 a
lrwxr-xr-x  1 root       wheel    1 Jan 15 17:38 b -> a

    现在我想修改b的属主:

以下是引用片段:
autoinstall# chown yayu b
autoinstall#
autoinstall# ls -l
-rw-r--r--  1 root       wheel    0 Jan 15 17:38 a
lrwxr-xr-x  1 root       wheel    1 Jan 15 17:38 b -> a

    很遗憾,失败了!确定yayu这个用户是存在的。于是上chinaunix问了一下,嗯,感谢ports 的回答。教训:学会man的好习惯!

    解决如下:加个“-h”参数

    在linux下man结果为:

以下是引用片段:
       -h, --no-dereference
              affect  each  symbolic  link  instead  of any referenced file (useful only on systems that can change the ownership of a symlink)

    在freebsd下man为:

以下是引用片段:
     -h      If the file is a symbolic link, change the user ID and/or the
             group ID of the link itself.


展开全文  
收起全文