Score:0

Why `Permission denied` for `ls` and `touch` when folder have `r` and `w` permissions for everybody?

ec flag

I've read rm: cannot remove directory/: Permission denied, noted answers to the question where permissions for directory were not provided missed restricted directory bit case, so I decided to learn deeper and stumbled upon the following for which I was not able to find answer by web search:

touch /media/drive/1/2
touch: cannot touch '/media/drive/1/2': Permission denied
ls /media/drive/1
ls: cannot access '/media/drive/1/1': Permission denied

sudo ls -la /media/drive/1
total 0
drw-rw-rw- 2 alex alex 60 Oct  5 08:36 .
drwxrwxrwx 4 root root 80 Oct  5 08:36 ..
-rw-rw-r-- 1 alex alex  0 Oct  5 08:36 1

BTW: why total 0?

Info page (info '(coreutils) File permissions'):

  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.

Internet search basically tells the same. Folder 1 has both read and write, why operations fail? For x permission to access what access means here?

Martian2020 avatar
ec flag
@mook765, it answers for actual behaviors , but not why `x` is needed in spite of docs telling otherwise and comments telling me in earlier UNIX `x` was needed for `cd`, not `ls`.
Martian2020 avatar
ec flag
@muru, please see comment to mook765
Martian2020 avatar
ec flag
@muru, looks to me now (Ubuntu 20) `x` is redundant as it adds no permission by itself (for directory).
muru avatar
us flag
@Martian2020 It does. Even in Ubuntu 20.04. `x` is need to actually enter the directory and access anything in it. Your `ls` command is presumably an alias that actually runs `ls -l`, which tries to examine each entry in the directory, which cannot work without the `x` permission unless you're root.
Martian2020 avatar
ec flag
@muru, maybe I have not made myself clear. Let me rephrase: Any use cases for -x +r/w? Or reverse +x -rw?
muru avatar
us flag
`x +r/w`, not of much practical use. `+x, -rw` is pretty common when you want to give a user access to some specific file or subdirectory, but otherwise not see or modify other things in the directory.
vanadium avatar
cn flag
folder `1` does not show up as a folder in your ls output. Probably time to check the file system thoroughly.
Martian2020 avatar
ec flag
@muru, thanx. Reading about what directory inode contains (just name and pointer) helped too, I wish info/man page was a bit more informative about such things. One issue puzzles me: I tried to `mv` a file to folder with `+rw -x`, `perm denied` - but I have write to directory, the system could have written file inode pointer along with name to the directory. Any reason it does not work that way? Use case would be you can drop the file to directory but not be able to access/change it later.
muru avatar
us flag
Think of `mv foo bar/` as `mv foo bar/foo` => without `x` on `bar`, `bar/foo` can't be accessed (even if it doesn't currently exist), and so the operation cannot be permitted.
Martian2020 avatar
ec flag
@muru, so implementation dependent? Because seeing `read` system can check for already existing files of same name.
muru avatar
us flag
No, I'm not aware of any implementation that will allow that. Sure you can check if the file exists, but you still can't access the `bar/foo` path without `x` on bar.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.