Browse > Home / How-To / How to list numeric file permissions on Linux

| Subscribe via RSS

How to list numeric file permissions on Linux

January 25th, 2007 Posted in How-To

Anybody who installs php or cgi scripts on linux webservers knows, that you often have to adjust the permissions for the script files or folders. In the majority of cases the guidelines for the permission settings are documented for those scripts in numeric notation. (for example: 755 or 777 etc.)

If you check your file permissions on your server via command line (for example with the ls -l command), it will show your permissions in symbolic mode (like drwxr-xrx …). Thats quite unhandy if you want to compare the actual permissions with those you should have.

“No Problem” – I thought. Can´t be that hard to find a way to list the permissions in numeric notation. Far from it. I did not find a solution how to do that easily.

So i had to ask my friend Thilo who is a native linux speaker ;.). The outcome was if not an easy at least a working command:
for i in $(ls) ; do bla=$( stat -c “%a” $i);echo “$i: $bla”; done
if somebody knows an easier way, please let me know. (comment on this post)

4 Responses to “How to list numeric file permissions on Linux”

  1. Garry Says:

    You can use stat directly.

    stat -c “%a %n” *

    will output the octal file permissions and file name of all files in the current directory.

    stat -c “%a %n” /home/mydir/source/*

    will do the same for all files in /home/mydir/source/ (if you leave off the “/*” at the end, stat will just tell you that it’s a directory).


  2. Garry Says:

    While I’m at it, there’s a handy alias that will display the “human readable” permissions, the numeric permissions, the size in bytes (padded to 8 characters), and time of last modification (truncated at 19 characters), and the filename, including any provided path spec:

    alias d=’stat -c “%A (%a) %8s %.19y %n” ‘

    You would use the command thus:

    d Src/*

    -rw-r–r– (644) 3808 2009-03-27 17:12:34 Src/DaemonClient.cpp
    -rw-r–r– (644) 8898 2009-04-02 10:29:23 Src/DaemonObject.cpp
    -rw-r–r– (644) 4782 2009-03-31 11:39:12 Src/main.cpp

    Hope someone finds that useful.


  3. Titusz Says:

    thanks Garry… that makes it much easier…


  4. Florin Says:

    Great! I was looking for a command to list permission in octal, of a file. Now i found it. Thanks Garry.


Leave a Reply