I have an octal representing Linux file permissions.
The permissions are currently, I.E 0o640
and I want to set the group bit to 6 (so 0o660
). I saw that I can set the bit in the nth place here but the results I get are peculiar, I guess that it is because of the octal representation.
I Tried:
perm = 0o640
# Set the bit in the 2nd place (index 1) to 6.
new_perm = perm | (6<<1)
# new_perm is now 0o634 (wanted 0o660).
I'm doing something wrong I guess...
I also wonder what is the advantage of using octal instead of regular integers in Python when working with file permissions.
Thanks!