0

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
  • 181
  • 1
  • 10
  • @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 Oct 05 '21 at 06:26
  • @muru, please see comment to mook765 – Martian2020 Oct 05 '21 at 06:27
  • @muru, looks to me now (Ubuntu 20) `x` is redundant as it adds no permission by itself (for directory). – Martian2020 Oct 05 '21 at 06:28
  • 1
    @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. – muru Oct 05 '21 at 06:37
  • @muru, maybe I have not made myself clear. Let me rephrase: Any use cases for -x +r/w? Or reverse +x -rw? – Martian2020 Oct 05 '21 at 06:52
  • 1
    `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. – muru Oct 05 '21 at 07:01
  • folder `1` does not show up as a folder in your ls output. Probably time to check the file system thoroughly. – vanadium Oct 05 '21 at 07:15
  • @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. – Martian2020 Oct 05 '21 at 07:21
  • 1
    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. – muru Oct 05 '21 at 07:58
  • @muru, so implementation dependent? Because seeing `read` system can check for already existing files of same name. – Martian2020 Oct 05 '21 at 08:11
  • 1
    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. – muru Oct 05 '21 at 08:12

0 Answers0