免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1920 | 回复: 5
打印 上一主题 下一主题

apue2 4.7题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-09-14 18:41 |只看该作者 |倒序浏览
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系统

论坛徽章:
0
2 [报告]
发表于 2008-09-14 19:15 |只看该作者

回复 #1 uid500 的帖子

bash shell一般用户创建文件,默认属性是664(umask 002,/etc/bashrc里面有设定)
你也许是root用户,或者自定义的umask 022
看看~/.bashrc

[ 本帖最后由 liotta 于 2008-9-14 19:19 编辑 ]

论坛徽章:
0
3 [报告]
发表于 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 编辑 ]

论坛徽章:
0
4 [报告]
发表于 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 编辑 ]

论坛徽章:
0
5 [报告]
发表于 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.

论坛徽章:
0
6 [报告]
发表于 2008-09-14 22:51 |只看该作者
哈哈  谢谢各位了,小第理解了
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP