Chinaunix

标题: apue2 4.7题 [打印本页]

作者: uid500    时间: 2008-09-14 18:41
标题: apue2 4.7题
apue2 的第4,7题
Note in output from the ls command in Section 4.12 that the files core and core.copy have different access permissions. If the umask value didn't change between the creation of the two files, explain how the difference could have occurred.


  $ cat core > core.copy
       $ ls -l core*
       -rw-r--r--  1 sar      8483248 Nov 18 12:18 core
       -rw-rw-r--  1 sar      8483248 Nov 18 12:27 core.copy
       $ du -s core*
       272     core
       16592   core.copy


首先,这个问题我想不通,为什么cat 以后core.copy的属性就变了呢

然后我在我的计算机上试了,文件的属性并不变啊   这是什么问题啊
我的是debian系统
作者: liotta    时间: 2008-09-14 19:15
标题: 回复 #1 uid500 的帖子
bash shell一般用户创建文件,默认属性是664(umask 002,/etc/bashrc里面有设定)
你也许是root用户,或者自定义的umask 022
看看~/.bashrc

[ 本帖最后由 liotta 于 2008-9-14 19:19 编辑 ]
作者: uid500    时间: 2008-09-14 19:32
Note in output from the ls command in Section 4.12 that the files core and core.copy have different access permissions. If the umask value didn't change between the creation of the two files, explain how the difference could have occurred.


  $ cat core > core.copy
       $ ls -l core*
       -rw-r--r--  1 sar      8483248 Nov 18 12:18 core
       -rw-rw-r--  1 sar      8483248 Nov 18 12:27 core.copy
       $ du -s core*
       272     core
       16592   core.copy


首先上面的英文部分是书中的原文
$ ls -l core*
       -rw-r--r--  1 sar      8483248 Nov 18 12:18 core
       -rw-rw-r--  1 sar      8483248 Nov 18 12:27 core.copy
这里的core 和core.copy的文件属性变了  core.copy多了一个组可读
我是用的umask 022和文中用的一样但是在我的机子上试验的时候core.copy的属性没有变

我的问题是1为什么书上说是变的呢  ,想不通
               2为什么我系统上的就没有变了
谢谢二楼       根据二楼的提示我把umask改为664 发现cat core > core.copy以后的文件属性确实变了 ,多了一个组可读,和其他用户可读,那着有是什么道理啊,弄糊涂了(其实好象也是不变的 首先建一个文件  然后在用cat core > core.copy 也没有多什么属性啊)

[ 本帖最后由 uid500 于 2008-9-14 19:38 编辑 ]
作者: liotta    时间: 2008-09-14 20:47
标题: 回复 #3 uid500 的帖子
这个例子是说明umask的作用:
书中shell的umask是002,表示默认生成的文件属性为664(-rw-rw-r--),而
rw-r--r--  1  core 的文件属性为644,经过cat生成的文件属性是默认是664.

而你的shell的umask是022,表示默认生成的文件属性为644,经过cat生成的文件是644,也是符合umask的作用的
你想看得清楚一点就先改一下core的属性(chmod 666 core)

不要乱改umask !
基本知识见http://linux.vbird.org/linux_basic/0210filepermission.php

[ 本帖最后由 liotta 于 2008-9-14 21:06 编辑 ]
作者: insmile    时间: 2008-09-14 21:45
书后面给的答案:4.7 The kernel has a default setting for the file access permission bits when it creates a new core file. In this example, it was rw-r--r--. This default value may or may not be modified by the umask value. The shell also has a default setting for the file access permission bits when it creates a new file for redirection. In this example, it was rw-rw-rw-, and this value is always modified by our current umask. In this example, our umask was 02.
作者: uid500    时间: 2008-09-14 22:51
哈哈  谢谢各位了,小第理解了




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2