ptg10805159
Appendix C Chapter 4 Solutions 909
$umask 777
$date > temp.foo
$ls -l temp.foo
---------- 1 sar 29 Feb 5 14:06 temp.foo
4.3 The following shows what happens when user-read permission is turned off:
$date > foo
$chmod u-r foo turn off user-read permission
$ls -l foo verify the file’spermissions
--w-r--r-- 1 sar 29 Feb 5 14:21 foo
$cat foo and try to read it
cat: foo: Permission denied
4.4 If we try,using eitheropenorcreat, to create a file that already exists, the file’s
access permission bits arenot changed. We can verify this by running the
program from Figure4.9:
$rm foo bar delete the files in case they already exist
$date > foo create them with some data
$date > bar
$chmod a-r foo bar turn off all read permissions
$ls -l foo bar verify their permissions
--w------- 1 sar 29 Feb 5 14:25 bar
--w------- 1 sar 29 Feb 5 14:25 foo
$./a.out run program from Figure4.9
$ls -l foo bar check permissions and sizes
--w------- 1 sar 0 Feb 5 14:26 bar
--w------- 1 sar 0 Feb 5 14:26 foo
Note that the permissions didn’t change but that the files weretruncated.
4.5 The size of a directory should never be 0, since thereshould always be entries for
dot and dot-dot. The size of a symbolic link is the number of characters in the
pathname contained in the symbolic link, and this pathname must always contain
at least one character.
4.7 The kernel has a default setting for the file access permission bits when it creates a
newcorefile. In this example, it wasrw-r--r--.This default value may or
may not be modified by theumaskvalue. 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 wasrw-rw-rw-,and this value is always modified by our current
umask.Inthis example, ourumaskwas 02.
4.8 We can’t usedu,because it requires either the name of the file, as in
du tempfile
or a directory name, as in
du.
But when theunlinkfunction returns, the directory entry fortempfileis gone.
Thedu .command just shown would not account for the space still taken by