Confused about directory permissions

Issues related to applications and software problems and general support
Post Reply
bodisha
Posts: 54
Joined: 2015/06/06 23:55:29

Confused about directory permissions

Post by bodisha » 2020/01/03 19:23:50

Hello... And thanks in advance to anyone that can offer me some guidance on this

I was playing with directory permissions to make sure I understood them... And created some test directories with various permissions
drwx------. 2 kmg kmg 41 Jan 3 12:44 suball
d-w-------. 2 kmg kmg 45 Dec 31 09:35 subwrite
dr--------. 2 kmg kmg 43 Dec 30 08:40 subread
d--x------. 2 kmg kmg 43 Dec 26 17:10 subexec
dr-x------. 2 kmg kmg 39 Dec 26 13:57 subreadwrite
I have files under each directory with identical permissions (644) and was able to append some text to all of them (using an echo command) except to the file under the subread directory... My understanding is an append should be successful because the write permission was set on the files themselves... And it has nothing to do with the directory... But when I tried to do this with the subread directory I received a "permission denied" error. Which confuses me.... I thought the append action would be dependent on the permissions of the file
-rw-r--r--. 1 kmg kmg 14 Dec 30 08:37 subread.txt
I don't understand why this would fail only for the subread directory... Can someone straighten me out on this?

THANKS!

lightman47
Posts: 1521
Joined: 2014/05/21 20:16:00
Location: Central New York, USA

Re: Confused about directory permissions

Post by lightman47 » 2020/01/03 21:24:24

And it has nothing to do with the directory
As I understand it -

To be able to GET TO the file, you need X permission on the directory - as set up, subread only has R permission for the owner. After that, there may be issues with appending - for which you'd need W permissions.

MartinR
Posts: 714
Joined: 2015/05/11 07:53:27
Location: UK

Re: Confused about directory permissions

Post by MartinR » 2020/01/03 22:56:57

From https://www.gnu.org/software/coreutils/ ... -Structure:
There are three kinds of permissions that a user can have for a file:
  1. permission to read the file. For directories, this means permission to list the contents of the directory.
  2. permission to write to (change) the file. For directories, this means permission to create and remove files in the directory.
  3. permission to execute the file (run it as a program). For directories, this means permission to access files in the directory.
For directories, if you can list the directory (ie read), you can use ls and wildcards to see what is in the directory. Remember that a directory is just a table linking filenames to the i-nodes. Accessing a file of which you already know the name is covered by execute. With only x access you cannot read the list of files, however with read access you can of course find the i-node, therefore read is a superset of execute.

Write access for a directory allows you to modify the directory file, ie create or delete. I would not have expected an append to be blocked without write, but perhaps it is extended in its meaning. Would it be possible to reproduce the exact command which failed in the subread case?

Post Reply