How to read files permissions in numeric format?

When we do: ls -l we get something like:
-rw-r--r-- 1 jm jm 0 05-23 11:41 test
I’m aware that in numeric format it’s 644.
Is there a way to read it somehow to get:
644 1 jm jm 0 05-23 11:41 test
Or something similar?

Please read my very elaborate tutorial on the subject… :arrow_down:

:slight_smile:

5 Likes

I’ll definitely do but I’m curious right now :slight_smile:
Is there an answer to my question or just explanation of the subject?

I know that read is 4 write is 2 and execute is 1, and we can add them to get desired permission.

stat filename :wink:

or example (use %a read man):

stat -c '%n %U:%G %a = %A %F' $HOME/*
echo -e "$(stat -c '%n %U:%G \033[32m%a\033[0m = %A %F' $HOME/*)"
6 Likes

Exactly what I needed. Thank you!!! :smiley:

Cool.

Just an alternative… If --printf rather -c is used, the echo -e and command substitution can be eliminated. A ‘\n’ needs to be added though.

gnu doc

2 Likes

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.