in reply to Chmod a+x a file in Perl
*Nix permissions are based around 3 categories (user, group, and other) and 3 values (read, write, and execute). A value such as 0777 the octal (base-8) value that represents giving each category each of the permissions. The value '7' isn't being "lucky" here-it is the sum of the three bits used to represent the values. The actual meaning of each bit in the value is:
| \ | Read | Write | Execute | Translation ('rwx') |
| 0 | 0 | 0 | 0 | --- |
| 1 | 0 | 0 | 1 | --x |
| 2 | 0 | 1 | 0 | -w- |
| 3 | 0 | 1 | 1 | -wx |
| 4 | 1 | 0 | 0 | r-- |
| 5 | 1 | 0 | 1 | r-x |
| 6 | 1 | 1 | 0 | rw- |
| 7 | 1 | 1 | 1 | rwx |
Now take those values and apply by user to your example of 0777:
| \ | User | Group | Other |
| Read | 4 | 4 | 4 |
| Write | 2 | 2 | 2 |
| Execute | 1 | 1 | 1 |
| Total | 7 | 7 | 7 |
To do the equivalent of 'a+x' you would need to get the current permissions (via stat) and OR ('|') that value with 0111. For each category of user, this gives you the following permissions:
| A (rwx) | B | A|B (rwx) |
| 0 (---) | 1 | 1 (--x) |
| 1 (--x) | 1 | 1 (--x) |
| 2 (-w-) | 1 | 3 (-wx) |
| 3 (-wx) | 1 | 3 (-wx) |
| 4 (r--) | 1 | 5 (r-x) |
| 5 (r-x) | 1 | 5 (r-x) |
| 6 (rw-) | 1 | 7 (rwx) |
| 7 (rwx) | 1 | 7 (rwx) |
Hope that helps.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Chmod a+x a file in Perl
by atcroft (Abbot) on Feb 18, 2022 at 05:39 UTC |