title: unix permissions converter in symbolic notation (including sticky bit)
body: <p>I need to get <code>Access rights in</code> <strong>more</strong> <code>human readable</code> format for file or folder with a <a href="http://permissions-calculator.org/symbolic/" rel="nofollow noreferrer">symbolic</a> notation like this <code>u=rwx,g=srwx,o-rwx</code> (possibly sticky bits)</p>
  
  <ul>
  <li>Using <code>stat --format '%a'</code>, I obtain a result with format <code>2770</code>, octal format</li>
  <li>Using <code>stat --format '%A'</code>, I obtain a result with format <code>drwxrws---</code>, human readable</li>
  </ul>
  
  <p>I need a command to obtain a format like <code>u=rwx,g=srwx,o-rwx</code> <em>(compatible with <code>chmod symbolic modes</code> )</em></p>
  
  <ul>
  <li><code>[u|g|o]</code> : for <code>user</code>/<code>group</code>/<code>other</code> or <code>a</code> for all</li>
  <li><code>[=]</code>     : for rights granted</li>
  <li><code>[rwxst]</code> : list of rights granted no order importance</li>
  <li><code>[-rwx]</code>  :for right revoked (if no right granted)</li>
  </ul>
  
  <p>I have tried this ( But it doesn't handle all cases, specialy sticky bits) :</p>
  
  <pre><code>stat --format '%A' temp |
      sed -E 's/^.(...)(...)(...)/u=\1,g=\2,o=\3/g' | # split by triplet
      sed 's/=---/-rwx/g' | # revoker grants
      sed 's/rws/srwx/g'  | # setgid with x ...
      sed 's/--S/s/g'     | # setgid without x ...
      sed ... nead more transormation... # manage  sticky bit setuid setgid
  </code></pre>
  
  <p>I search a more elegant way.</p>
  
  <p>example input ==> output </p>
  
  <ul>
  <li><code>drwxrws---</code> ==> <code>u=rwx,g=srwx,o-rwx</code> (begin by d ==> directory)</li>
  <li><code>drwxrwxrwx</code> ==> <code>u=rwx,g=rwx,o=rwx</code> or <code>ugo=rwx</code> or <code>a=rwx</code></li>
  <li><code>-r-xrw-r--</code> ==> <code>u=rx,g=rw,o=r</code>      (begin by - ==> regular file)</li>
  <li><code>-rwx--S---</code> ==> <code>u=rwx,g=s,o-rwx</code>    (S in uppercase)</li>
  <li><code>------s--t</code> ==> <code>u=-srwx,g=sx,o=xt</code>  (Stickybit)</li>
  </ul>
  
  <p>input format ==> like commands <code>stat</code> or <code>ls -al</code><br />
  output format==> must be compatible with <code>chmod</code></p>
  
  <p>This complete version seems works, but I'm sure we can simplify it, <em>( ie without multiple sed )</em></p>
  
  <pre><code>stat --format '%A' a |
  sed -E 's/^.(...)(...)(...)/u=\1,g=\2,o=\3/g' | # split by triplet    
  sed -E 's/s/xs/g'          | # setgid ou setuid with x ...
  sed -E 's/t/xt/g'          | # sticky bit with x ...    
  sed -E 's/S/s/g'           | # setgid ou setuid without x ...
  sed -E 's/T/t/g'           | # sticky bit alone
  sed -E 's/-//g'            | # remove -
  sed -E 's/=(,|$)/-rwx\1/g'   # revoker grants
  </code></pre>