How can I reset permission to default according to the mask, so they will have permissions set as the file was just created
Example of what I want to achieve:
umask
is set to 0022
so
touch file
mkdir directory
file's permissions now are rw-r--r--
directory's permissons now are rwxr-xr-x
chmod 777 file
chmod 777 directory
file's permissions now are rwxrwxrwx
directory's permissions now are rwxrwxrwx
is there a way to reset perms back to default so file will be rw-r--r--
and directory rwxr-xr-x
using chmod
?
chmod =rwx file
, not sure what exactly it does but looks like it resets permissions to default too but only for directories – lllook Dec 16 '15 at 23:0810#
. For example:chmod $((10#0666 - 10#$(umask))) file
– John Karahalis Jan 05 '21 at 20:46printf "%o\n" "$(( 0666 & ~$(umask) ))"
should work. Zsh needsprintf "%o\n" "$(( 8#0666 & ~8#$(umask) ))"
, but then that doesn't work in Dash. – ilkkachu May 25 '21 at 14:49chmod =rwx file
also works, it sets the permissions to 0777 modified by the umask. See the sentences with "if who is not specified" in https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/utilities/chmod.html – ilkkachu May 25 '21 at 14:52$((0666 - 0444))
in Bash is equal to decimal 146 but$((10#0666 - 10#0444))
is equal to decimal 222. In any case, you may be right that bitwise is the way to go to avoid confusion. – John Karahalis May 28 '21 at 03:00