Chinaunix首页 | 论坛 | 博客
  • 博客访问: 532494
  • 博文数量: 111
  • 博客积分: 2109
  • 博客等级: 上尉
  • 技术积分: 1124
  • 用 户 组: 普通用户
  • 注册时间: 2012-04-25 12:11











分类: 其他平台

2013-04-08 20:04:44


默认情况下,cp 命令会将原文件的属主更改为 EUID。
鸟哥的书上说 cp 的 -p 选项是可以用于在复制时保留源文件的permission.
可是我发现原来 cp -p 只是在root用户复制其他用户文件时才会保留原来的permission(permission不仅仅是那几个rwx,也包括属主、属组),而在EUID为普通用户使用时依旧更改属主和属组。
不过 使用 -p 选项可以使复制的目标文件和源文件保持相同的 mtime .

-p 等于--preserve=模式,所有权,时间戳
      --preserve[=属性列表 保持指定的属性(默认:模式,所有权,时间戳),如果
 可能保持附加属性:环境、链接、xattr 等
      --sno-preserve=属性列表 不保留指定的文件属性
      --parents 复制前在目标目录创建来源文件路径中的所有目录



关于UID 以及EUID :


4.4. Set-User-ID and Set-Group-ID

Every process has six or more IDs associated with it. These are shown in Figure 4.5.

Figure 4.5. User IDs and group IDs associated with each process

real user ID
real group ID

who we really are

effective user ID
effective group ID
supplementary group IDs

used for file access permission checks

saved set-user-ID
saved set-group-ID

saved by exec functions

Normally, the effective user ID equals the real user ID, and the effective group ID equals the real group ID.

Every file has an owner and a group owner. The owner is specified by the st_uid member of the stat structure; the group owner, by the st_gid member.

When we execute a program file, the effective user ID of the process is usually the real user ID, and the effective group ID is usually the real group ID. But the capability exists to set a special flag in the file's mode word (st_mode) that says "when this file is executed, set the effective user ID of the process to be the owner of the file (st_uid)." Similarly, another bit can be set in the file's mode word that causes the effective group ID to be the group owner of the file (st_gid). These two bits in the file's mode word are called the set-user-ID bit and the set-group-ID bit.

For example, if the owner of the file is the superuser and if the file's set-user-ID bit is set, then while that program file is running as a process, it has superuser privileges. This happens regardless of the real user ID of the process that executes the file. As an example, the UNIX System program that allows anyone to change his or her password, passwd(1), is a set-user-ID program. This is required so that the program can write the new password to the password file, typically either /etc/passwd or /etc/shadow, files that should be writable only by the superuser. Because a process that is running set-user-ID to some other user usually assumes extra permissions, it must be written carefully. We'll discuss these types of programs in more detail in Chapter 8.

Returning to the stat function, the set-user-ID bit and the set-group-ID bit are contained in the file's st_mode value. These two bits can be tested against the constants S_ISUID and S_ISGID.

加入了大一时候利用文件存储data的意识。。真是太愚蠢了。Every thing is file.或许我刚刚理解了一点。

阅读(812) | 评论(0) | 转发(0) |