Elwood Hopkins
Elwood Hopkins

Reputation: 171

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?

Upvotes: 8

Views: 3812

Answers (4)

Lukasz Siemiradzki
Lukasz Siemiradzki

Reputation: 336

  1. You may be blind and still be able to write:

     $ touch a
     $ chmod 0200 a
     $ ls -ln  a
     --w------- 1 1000 1000 4 Jul 19 15:13 a
     $ cat a
     $ cat: a: Permission denied
     $ echo "secret message" >> a
     $ chmod 0400 a
     $ cat a
     secret message
    
  2. Nope :)

Upvotes: 8

devnull
devnull

Reputation: 123448

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

Upvotes: 8

KevinDTimm
KevinDTimm

Reputation: 14376

1) write only means write only - so, no way to do so
2) No

Upvotes: 1

Norwæ
Norwæ

Reputation: 1575

A file can be a lot of things in unix-like systems. It might, for example be a pipeline, where a user might submit data to, but not receive data from. So no, a write permission does not imply read.

Another example might be a directory where the user can deposit data (potentially destroying existing data), but not read what others have deposited.

Upvotes: 5

Related Questions