Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unix File Permissions - Does Write Imply Read?

If a file had write permissions only, how could a user exercise his right to edit the file if he could not read it?

Does 'write' imply 'read' in Unix?

like image 504
Elwood Hopkins Avatar asked Jul 19 '13 13:07

Elwood Hopkins


1 Answers

Read, write, execute permissions in Unix/Linux are independent. It's possible to have write permissions without the read permission. For binary files, you might have seen that read permission isn't granted but execute permission enables you to execute it. On the other hand, a shell script or any other file that needs to be interpreted needs read permissions in order to execute.

Simply providing write permissions without read would enable you to write (also delete) the file without being able to read it.

The following should be self-explanatory:

$ touch foo
$ ls -l foo
-rw-rw-r-- 1 devnull devnull 0 Jul 19 12:00 foo
$ chmod -r foo
$ ls -l foo
--w--w---- 1 devnull devnull 0 Jul 19 12:00 foo
$ cat foo
cat: foo: Permission denied
$ echo hey > foo
$ ls -l foo
--w--w---- 1 devnull devnull 4 Jul 19 12:00 foo
$ cat foo
cat: foo: Permission denied
$ > foo
$ ls -l foo 
--w--w---- 1 devnull devnull 0 Jul 19 12:00 foo
$ rm -f foo 
$ ls -l foo
ls: cannot access foo: No such file or directory
like image 102
devnull Avatar answered Sep 26 '22 02:09

devnull