Today I took LPIC 101-500 exam and I passed but one question keeps bothering me. The question was:
Given the following permissions -rw-r----- what umask should be applied to make all files have the same permissions? My reasoning is as follows (please correct me if I'm wrong):
- indicates that this is a regular file
r - 4
w - 2
- - 0
r - 4
- - 0
- - 0
- - 0
- - 0
- - 0
which gives 640 permissions.
Now, I know that umask is essentially an inverse of permissions so this comes down to the following equation:
777
-640
-----
137
So my answer would be 137, however there was no answer that included this result and I probably got this answer wrong. What am I missing?
% umask 137 ; touch xx ; ls -l xx
gets the result-rw-r----- 1 sweh sweh 0 Mar 16 18:45 xx
– Stephen Harris Mar 16 '22 at 22:46touch
or shell>
) creates a file it specifies a mode. Typically that's 0666. However an application such asgcc
will create the final executable with 0777 (because we normally wantx
set). That mode is "AND !umask" which results in the permissions. Similarly directory creation is passed a mask; normally that's 0777 but it doesn't have to be. It's purely up to the program that's doing the creation. So if I wrote a program that didmkdir("xyzzy",0700)
oropen("foo",O_RDWR|O_CREAT,0700)
then the permissions would be rwx------ (before umask). – Stephen Harris Mar 16 '22 at 23:49mask
. What each number is doing is masking one or more of the bits. The default umask for most systems is022
and that gives directories755
permissions and files644
permissions (same as directories w/o execute bit). Your answer of137
is correct but rather than thinking of it as coming via subtraction, think of it as what it's actually doing which is masking the execute bit for the owner, the write and execute bits for the group, and read, write, and execute for everyone else. – Nasir Riley Mar 16 '22 at 23:58umask
works (briefly) and where default permissions come from. – Stephen Kitt Mar 17 '22 at 05:39640
? – Kusalananda Apr 03 '22 at 17:46