utility to convert between permission list and octal chmod format?

Is there a GUI app or command-line utility that will translate between rwx... type file permssion string and the corresponding chmod octal format of that?


I do understand what octal is and how one manually can take such a permission string and represent it in octal, and vice versa. It's just a pain having to do so all the time. Hence my question, which is asking for a little shortcut for doing the same thing.

iMac, OS X Mountain Lion, 3.4GHz Corei7, 16GB, SSD + 2T HD

Posted on May 22, 2013 5:29 PM

Reply
18 replies

May 22, 2013 8:16 PM in response to Linc Davis

Linc Davis wrote:


$ ls -l foo

-rw------- 1 me staff 0 <date> <time> foo

$ stat -f %Lp foo

600

I do already know how to find out the rwx permission string of a file using ls -l, and how to find out the octal permissions representation using stat -f %Lp.


But that's not what I asked for! Say I'm reading docs about some program that say to set the permissions to 772. I want to know the corresponding string -- without having to do he (admittedly, little bit) of arithmetic involved. And conversely.

May 22, 2013 8:18 PM in response to William Lloyd

William Lloyd wrote:


Have you considered Batchmod?


http://www.lagentesoft.com/batchmod/

I already use Batchmod, where I can enter permissions in either format -- octal or rwx string. But that's not what I asked about. I want some little utility that, even for a file I don't have yet (e.g., one I'm about to install), translates from either of the two formats to the other.

May 22, 2013 8:37 PM in response to murrayE

Open the AppleScript Editor in the /Applications/Utilities/ folder and run:


set the_string to "4775"

set new_string to "-"

if (count the_string) is 4 then

set the_list to items 2 thru 4 of the_string

repeat with this_char in the_list

if (this_char as number) is in {4, 5, 6, 7} then

set new_string to new_string & "r"

else

set new_string to new_string & "-"

end if

if (this_char as number) is in {2, 3, 6, 7} then

set new_string to new_string & "w"

else

set new_string to new_string & "-"

end if

if (this_char as number) is in {1, 3, 5, 7} then

set new_string to new_string & "x"

else

set new_string to new_string & "-"

end if

end repeat

set new_string to items of new_string

if (item 1 of the_string as number) is in {4, 5, 6, 7} and item 4 of new_string is "x" then set item 4 of new_string to "s"

if (item 1 of the_string as number) is in {4, 5, 6, 7} and item 4 of new_string is "-" then set item 4 of new_string to "S"

if (item 1 of the_string as number) is in {2, 3, 6, 7} and item 7 of new_string is "x" then set item 7 of new_string to "s"

if (item 1 of the_string as number) is in {2, 3, 6, 7} and item 7 of new_string is "-" then set item 7 of new_string to "S"

if (item 1 of the_string as number) is in {1, 3, 5, 7} and item 10 of new_string is "x" then set item 7 of new_string to "t"

if (item 1 of the_string as number) is in {1, 3, 5, 7} and item 10 of new_string is "-" then set item 7 of new_string to "T"

return new_string as string

end if

if (count the_string) is 10 then

set new_number to 0

considering case

if item 2 of the_string is "r" then set new_number to new_number + 400

if item 3 of the_string is "w" then set new_number to new_number + 200

if item 4 of the_string is "x" then set new_number to new_number + 100

if item 4 of the_string is "s" then set new_number to new_number + 4100

if item 4 of the_string is "S" then set new_number to new_number + 4000

if item 5 of the_string is "r" then set new_number to new_number + 40

if item 6 of the_string is "w" then set new_number to new_number + 20

if item 7 of the_string is "x" then set new_number to new_number + 10

if item 7 of the_string is "s" then set new_number to new_number + 2010

if item 7 of the_string is "S" then set new_number to new_number + 2000

if item 8 of the_string is "r" then set new_number to new_number + 4

if item 9 of the_string is "w" then set new_number to new_number + 2

if item 10 of the_string is "x" then set new_number to new_number + 1

if item 10 of the_string is "t" then set new_number to new_number + 1001

if item 10 of the_string is "T" then set new_number to new_number + 1000

end considering

return new_number

end if


(83221)

May 23, 2013 6:24 AM in response to murrayE

Is there a reason you care?


chmod accepts rxw letters, no octal needed. For example the following sets the user permissons rwx, and the group and other permissions to rx (aka 755, but I did not need 755 to do this).


chmod u=rwx,go=rx file


You can also use + or - instead of = to add/remove permission bits, all using letters and no octal.


See "man chmod"

May 23, 2013 7:30 AM in response to BobHarris

BobHarris wrote:


Is there a reason you care?


chmod accepts rxw letters, no octal needed. For example the following sets the user permissons rwx, and the group and other permissions to rx (aka 755, but I did not need 755 to do this).


chmod u=rwx,go=rx file


You can also use + or - instead of = to add/remove permission bits, all using letters and no octal.


See "man chmod"

Yes: often in following instructions for configuring some program, I'm told to use chmod with an octal permission code. And many times, I doubt, often rightly, that such lax permissions are needed; or, in other situations, the octal code that's supposed to be used is, in fact, not lax enough.


I do know about the form of chmod with rwx strings you indicate.


I suppose I'm contiually surprised at how retrograde and computer-geekish documentation is in persisting to use octal permission codes in configuration instructions. Mind you, I'm not uncomfortable with octal: indeed, the second computer I ever programmed took all its instructions in octal (punched onto a paper tape).

May 23, 2013 7:33 AM in response to Topher Kessler

Topher Kessler wrote:


In searching around I just found this widget, which might be useful as well, and more convenient in that it will run in the dashboard: http://www.apple.com/downloads/dashboard/networking_security/unixpermissioncalcu latorwidget.html

Thanks for that pointer. I think this would be quite awkward to use, though, as I'd have to go to the Dashboard each time, rather than being able to type a command in Terminal, or use an app right on the Desktop, to do the translation.

May 23, 2013 7:47 AM in response to murrayE

I suppose I'm contiually surprised at how retrograde and computer-geekish documentation is in persisting to use octal permission codes in configuration instructions. Mind you, I'm not uncomfortable with octal:

Would you prefer decimal? 🙂


indeed, the second computer I ever programmed took all its instructions in octal (punched onto a paper tape).

PDP-8?


As I recall the first Unix was implemented on a PDP-7, and the PDP-11 where it became popular often used octal (most likely a carry over from the PDP-8 days). And since 3 permisson bits fix an octal character and that early Unix utilities had to fit in 56K of memory and data with an 8K stack, the first chmod did not have a symbolic input form, so octal made a lot of sense.


And changing the command API has a tendency to break other programs and scripts, so once established, they tend not to change over the years, just add non-conflicting options/features.

May 23, 2013 8:13 AM in response to BobHarris

BobHarris wrote:


I suppose I'm contiually surprised at how retrograde and computer-geekish documentation is in persisting to use octal permission codes in configuration instructions. Mind you, I'm not uncomfortable with octal:

Would you prefer decimal? 🙂


indeed, the second computer I ever programmed took all its instructions in octal (punched onto a paper tape).

PDP-8?


As I recall the first Unix was implemented on a PDP-7, and the PDP-11 where it became popular often used octal (most likely a carry over from the PDP-8 days). And since 3 permisson bits fix an octal character and that early Unix utilities had to fit in 56K of memory and data with an 8K stack, the first chmod did not have a symbolic input form, so octal made a lot of sense.


And changing the command API has a tendency to break other programs and scripts, so once established, they tend not to change over the years, just add non-conflicting options/features.


No, I'd prefer the u=..., g=..., o=... form and am intolerant of configuration documentation that doesn't say it that way instead of in octal. If one has used octal permissions for a long time, you don't have to waste time thinking what a particular number means -- you just realize it instantly from repetition.


[Getting OT: The computer in question was not, as I recall, a PDP-anything. And to program a loop, you literally formed a loop with the paper and taped the ends together before inserting it in the reader! This machine was quite a step down from the first computer I ever programmed, a Univac I (in assembler or numeric code, don't recall which). But fortunately, I was able to abandon that paper-tape machine after a couple of weeks and get to work with big iron, namely, an IBM 709, in FORTRAN.]

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

utility to convert between permission list and octal chmod format?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.