How to output file permissions in Octal Format

How to output file permissions in Octal Format

If you need to display permissions in Linux using Octal format, such as "644" rather than text output "-rw-r--r--" i've created this snippet for you to use filtering the values through Sed replacing with their numerical equivalent.

ls -la /pathtousehere | sed -e 's/--x/1/g' -e 's/-w-/2/g' -e 's/-wx/3/g' -e 's/r--/4/g'  -e 's/r-x/5/g' -e 's/rw-/6/g' -e 's/rwx/7/g' -e 's/---/0/g'

Directories will begin with the letter "D" followed by their converted Octal values. Sample output should look something like below:

-644.  1 root root     158 Nov 12 05:56 hosts
-644.  1 root root     370 Nov 12 05:56 hosts.allow
-644.  1 root root     460 Nov 12 05:56 hosts.deny
d755.  2 root root    4096 Sept  8 09:27 init
    • Related Articles

    • File Manager Cpanel / Fixing 403 correcting permissions.

      Learn how to troubleshoot WordPress 403 Forbidden error messages. We show you how to check for a corrupt .htaccess file. Diagnose faulty WordPress Plugins and checking for correct WordPress file permissions. Problem When you attempt to view your ...
    • Joomla/WordPress/CMS Permissions

      With the way that Hsphere and cPanel work in our shared environments, all CMS permissions should be set as follows: Directories - 755 Files - 644 If permissions have been changed or if you're unsure which permissions are which, you can run the ...
    • Extract IPV4 IP Addresses out of file

      Here's a very helpful method we can use to extract all IPV4 addresses out of a file, such as httpd.conf for for example. sed -n 's/\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}/\nip&\n/gp' /pathtofilehere | sed 's/ip//' Running it on my local resolv.conf file, ...
    • Chmod or change permissions on a directory through FTP client (FileZilla)

      Every file and folder that exists on your web server has a set of attributions, or permissions, that you can change using FileZilla. These permissions are assigned and tells the web server three things about the folder or file. On a very simplistic ...
    • PCLZIP_ERR_BAD_FORMAT (-10)

      If you get a PCLZIP_ERR_BAD_FORMAT (-10) error in hsphere webshell or other wise, set following in .htaccess or php.ini: mbstring.internal_encoding = "ISO-8859-1"