Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
    
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

4 Answers 4

up vote 16 down vote accepted

http://permissions-calculator.org/

share|improve this answer
4  
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. –  jrtayloriv Mar 18 '11 at 5:46
1  
Exactly. People are either too lazy or SE Reputation Score is what matters more than Googling. –  Dharmit Mar 18 '11 at 6:31
2  
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
2  
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. –  jrtayloriv Mar 18 '11 at 7:16
1  
Just wanted to thank @DarrylHein for the Q and jrtayloriv for the answer. I've been googling for this and couldn't find the right term. This Q came up and now I've found it. So asking here was absolutely the right thing to do as far as I'm concerned. Everyone's a winner. :-) –  Charles Roper Oct 9 '12 at 9:41

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. :)

share|improve this answer

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}'"
share|improve this answer
1  
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 at 6:04

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.