*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:
\ReadWriteExecuteTranslation ('rwx')
0000---
1001--x
2010-w-
3011-wx
4100r--
5101r-x
6110rw-
7111rwx

Now take those values and apply by user to your example of 0777:
\UserGroupOther
Read444
Write222
Execute111
Total777
Needless to say, giving anyone and everyone read, write, and execute permissions to a file is a BAD IDEA. (If there was ever a place where the old HTML blink tag might be approrpriate, it was the end of the previous sentence.)

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)BA|B (rwx)
0 (---)11 (--x)
1 (--x)11 (--x)
2 (-w-)13 (-wx)
3 (-wx)13 (-wx)
4 (r--)15 (r-x)
5 (r-x)15 (r-x)
6 (rw-)17 (rwx)
7 (rwx)17 (rwx)

Hope that helps.


In reply to Re: Chmod a+x a file in Perl by atcroft
in thread Chmod a+x a file in Perl by ovedpo15

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.