Friday, April 10, 2009

Display file permission in octal - Linux stat


File permissions in Linux can be displayed in octal format using Linux stat command.

from man page of Linux stat(1) command

%A Access rights in human readable form
%a Access rights in octal
%n File name

$ stat -c '%A %a %n' *

One sample output:

-rwxr-xr-x 755 netp.sh
drwxr-xr-x 755 old_dump
-rw-r--r-- 644 tdiff.sh

3 comments:

Unknown said...

Here's what I used to help my coworker fix his mistake.

On a known good server:
find /Pristine/Dir stat -c'chown %a %n' {} \; > /tmp/fix_perms.sh

On server with messed up perms:
chmod 700 /tmp/fix_perms.sh
/tmp/fix_perms.sh

GenSirHughGough said...

I think edcrosbys meant

find /Pristine/Dir -exec stat -c'chown %a %n' {} \; > /tmp/fix_perms.sh

Unknown said...

@GT, thanks.

© Jadu Saikia www.UNIXCL.com