为什么符号链接的权限默认为 all-permissive? [英] Why do the permissions of a symbolic link default to all-permissive?

查看:45
本文介绍了为什么符号链接的权限默认为 all-permissive?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用 ln 创建硬链接时:

When I create a hard link using ln:

ln testfile.txt testfile2.txt

文件硬链接由 inode 表中两个别名的相同 inode 编号使用 ls -li 确认,对于硬链接文件具有与原始名称文件相同的初始权限:

The file hardlink, confirmed by the same inode numbers for both aliases in the inode table with ls -li, has the same initial permissions for the hardlinked file as the file with the original name:

1222285 -rw-------   2 cs9****-**  cs******        98 Apr  9 15:00 testfile.txt
1222285 -rw-------   2 cs9****-**  cs******        98 Apr  9 15:00 testfile2.txt

然而,当我创建符号链接时:

When I create a symbolic link, however:

ln -s testfile.txt testfile3.txt

并再次确认前面的ls命令,显示是权限列表中带有l的软链接.但是,我的符号链接对所有用户类型(组、用户和其他)具有 all 权限:

and confirm again with the previous ls command, it show that it is a soft link with l in the permissions list. However, my symlink has all permissions for all user types (group, user, and other):

1222285 -rw-------   2 cs9****-**  cs******        98 Apr  9 15:00 testfile2.txt
1222285 -rw-------   2 cs9****-**  cs******        98 Apr  9 15:00 testfile.txt
1222286 lrwxrwxrwx   1 cs9****-**  cs******        12 Apr  9 15:08 testfile3.txt -> testfile.txt

这让我想到了我的问题:

This brings me to my questions:

  1. 为什么符号链接的初始权限是全许可的?我知道这是一种不同的文件类型,但为什么它以所有初始权限开始?从一个关于UNIX/Linux.SE的问题中,我发现一个目录的默认权限是777,恰好是相同的权限作为我的符号链接.目录和符号链接的权限是否有某种关联?

  1. Why are the initial permissions of a symbolic link all-permissive? I understand that is is a different filetype, but why does it start out with all initial permissions? From a question on UNIX/Linux.SE, I discovered that the default permissions for a directory are 777, which happen to be the same permissions as my symbolic link. Are the permissions of a directory and a symbolic link somehow related?

如何创建具有与原始权限相同的初始权限的符号链接?具体来说,我想要这样做的原因是我想编写一个 shell 脚本来进入单个文件系统并根据文件类型制作硬链接和软链接,我希望它保留权限.

How can I create symlinks that have the same initial permissions as the original? Specifically, the reason I want do this is that I want to write a shell script to go into a single file system and make hard links and soft links depending on the type of file, and I want it to preserve the permissions.

推荐答案

您在哪个平台上工作?如果您使用的是 linux,则根本不使用符号链接权限,因此无论它们的值如何,没人会在意.这在 BSD、OSX 或其他版本上可能有所不同.

Which platform are you working on? If you are on linux, then symlink permissions are not used at all, so whatever their value nobody cares. That could be different on BSD, OSX, or other flavors.

我想这个问题可以在 unix 子论坛上得到更好的回答.

This question could be better answered on unix sub forum I guess.

我发现目录的默认权限是 777

I discovered that the default permissions for a directory are 777

嗯,我真的不知道你从哪里得到的.文件和目录的默认权限(仍在 linux 上)仅取决于进程的 umask.参见man umask.

Hmm, I don't really know where you get that from. Default permissions for file and directories (still on linux) just depend on the umask of the process. See man umask.

这篇关于为什么符号链接的权限默认为 all-permissive?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆