What are the rules that determine file permissions of b after I do cp /path/to/a /p/t/b, depending on file permissions of /path/to/a and all dirs?
4
votes
1
answer
80
views
In [_Classic Shell Scripting_ from O'Reilly](https://learning.oreilly.com/library/view/classic-shell-scripting/0596005954/) , Arnold Robbins and Nelson H.F. Beebe write the follwing example:
>
> $ umask
> 023
> $ rm -f foo
> $ cp /bin/pwd foo
> $ ls -l /bin/pwd foo
> -rwxr-xr-x 1 root root 10428 2001-07-23 10:23 /bin/pwd
> -rwxr-xr-- 1 jones devel 10428 2002-09-21 16:37 foo
>
> The resulting permission string rwxr-xr--
reflects the loss of privileges: group lost write access, and other lost write and execute access.
Now, the 023
output at the beginning, tells me that in the current shell, _newly created files_ would have w
access removed for g
and wx
removed for o
, so while I understand that "other lost execute access", I don't get "group lost write access" nor "other lost write access", as neither of them had it in the first place.
Do you think it's just an inaccuracy of the wording of that comment, or am I missing something?
Furthermore, I've tried that on my system, and the result puzzles me a bit more:
$ umask
0023
$ cp /bin/pwd ~/foo
$ ls -l /bin/pwd ~/foo
-rwxr-xr-x 1 root root 35072 Jan 18 19:17 /bin/pwd*
-rw-r--r-- 1 myself myself 35072 Feb 1 12:54 /home/myself/foo
Now, the output of 0023
should mean removal of w
for g
and wx
for o
(of which only x
for o
was actually present, so it's the only one removed in this case), but instead it looks like the x
permission has been removed too for both u
and g
.
Why is that?
Where can I find all the rules that determine what happens, as far as permissions go, when I create and when I copy a file?
Asked by Enlico
(2258 rep)
Feb 1, 2025, 01:15 PM
Last activity: Feb 1, 2025, 04:52 PM
Last activity: Feb 1, 2025, 04:52 PM