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