# Is there a web based converter between rwx and the octal version?

I can never remember what the conversion is from something like `rw-r--r--` to `644`. Is there a simple web based converter between the 2?

-
It's just an octal number with the binary digits being mapped to rwxrwxrwx (user, group, other). – Keith Mar 18 '11 at 6:04
this can easilly be calculated by hand. or they can be displayed by `stat -c` ... – fromnaboo Apr 7 '13 at 16:54

This site provides an interactive way to see what permissions bits are set when various bits are set/unset.

The "calculator" looks like this:

-
I got this by Googling for "octal file permissions tool", by the way. Google is always a great first place to check when you have a question. – J. Taylor Mar 18 '11 at 5:46
Pst, I did try searching, but I couldn't find the right search term. Sorry to bother you so much...and give you some rep. – Darryl Hein Mar 18 '11 at 6:56
Darryl -- You didn't bother me. I'm trying to help you find answers to questions more easily on your own, so that when the time comes that you have a question that nobody is willing to answer for you, you might be able to answer it yourself. – J. Taylor Mar 18 '11 at 7:16
The link is broken now, which is why we generally discourage link-only answers, but it's hard to criticize when the question asked for a link – Michael Mrozek Nov 4 '12 at 19:45
The link is no longer broken. – Evan Teitelman Jan 14 '13 at 23:55

Octal is used for permissions because it's an easy conversion. Each group of `rwx` forms one octal digit. All you have to remember is the first 3 powers of 2: 4, 2, 1. `r` = 4, `w` = 2, `x` = 1.

`rw-r--r--` = `110 100 100` = `4+2+0 4+0+0 4+0+0` = `644`

-

I have this little alias that you can put in your .bashrc (or equivalent).

DISCLAIMER: I am not the author of the script, and I'm not sure who wrote it... but props to him/her for doing this.

``````alias lsp="ls -l --color |
awk '{k=0; for(i=0;i<=8;i++) k+=((substr(\\$1,i+2,1)~/[rwx]/)*2^(8-i));
if (k) printf(\" %0o \",k); print}'"
``````
-
Many thanks for that, @nico - here is the same code converted as a perl one-liner, and used in bash: `echo 'rwxrwxrw-' | perl -ne 'BEGIN{sub conv{ chomp(my \$ins=shift); my \$k=0; for(my \$i=0;\$i<=8;\$i++) { my \$tmps = ( substr(\$ins, \$i, 1) =~ /[rwx]/ ); \$k+= ( \$tmps*(2**(8-\$i)) ); }; if (\$k) { sprintf(" %0o ", \$k); } else { "??" ; }; }; } print(conv(\$_)."\n");'` would print "`776`". Cheers! – sdaau Jul 16 '14 at 6:04

Why do you need octal number in the first place?

I always use:

``````chmod o+x file   # all + eXecute permissions
chmod g-w file   # group - write perms
chmod u=r file   # user can just read
chmod ug=rw file # user,group = read and write
chmod a+w file   # user,group,others + write
``````

ugo(a) is easy to remember. However you can confuse o:=owner? o:=other? but what would be u, if o=owner? u:=user, therefore o=other.

Some comands like numerical permissions only. Okay, it's not hard to calculate, if you remember the two sequences: ugo + rwx.

``````    r   w   x  | Sum
u   4   2   1  | 7
g   4   -   1  |  5
o   4   2   -  |   6
---------------------
756
``````

Yes, very artificial.

When it comes to s and S I have to consult the manual. Maybe google next time. :)

-

I like this permissions calculator:
http://file-permissions.ninja

-
Normally, I would flag this for being a link-only answer, but since the OP was explicitly asking for a website, I will let it pass. Be aware though that link-only answers are often discouraged. – HalosGhost Oct 17 '14 at 20:11

This is by far the most convenient, and is besides I believe, exactly what you asked for originally:

http://ss64.com/osx/chmod.html

It is fully interactive, though you cannot edit the string "-r-x-------" but you can the octal or the checkboxes. Doing either updates the other.

From the same page:

Numeric (absolute) mode:

From one to four octal digits Any omitted digits are assumed to be leading zeros.

The first digit = selects attributes for the set user ID (4) and set group ID (2) and save text image (1) The second digit = permissions for the user who owns the file: read (4), write (2), and execute (1) The third digit = permissions for other users in the file's group: read (4), write (2), and execute (1) The fourth digit = permissions for other users NOT in the file's group: read (4), write (2), and execute (1)

The octal (0-7) value is calculated by adding up the values for each digit User (rwx) = 4+2+1 = 7 Group(rx) = 4+1 = 5 World (rx) = 4+1 = 5 chmod mode = 0755

-

I've created a calculator that performs this exact function: http://rowanstringer.com/unix-file-permissions-calculator/

-