The permits They are quite an interesting topic in the Unix world and one of the most valued peculiarities of this type of operating system. Linux implements this system of modes for the directories and files of the system, and that we can complement with other security layers such as the extended attributes that some file systems implement, or also other types of security systems such as access control lists or ACL.
In some articles we have talked about the modes or permissions, whatever you want to call them, and surely you already know that we can see the permissions that our directories and files with a simple command ls -l, but in the console it will show us the form of letters as we already know. On the other hand, we can also use this same notation or the octal one to modify these permissions using the chmod command, as you already know ... But what happens if we want to list the permissions in octal form?
Well, in order to see octal notation We can use different procedures, although one of the simplest is through the stat command:
With the previous command we will see a lot of information about this specific file, in the example / etc / passwd. But if we just want to see the o mode permissions in octal format, you can use:
stat -c '%a' /etc/passwd
Between the formats and possibilities Available, which you can see with man stat, are also% A to see the format with letters, and many other options to filter the complete output and only show some of the fields that are obtained if we do not specify anything. For example, if we want to be shown both ways of viewing the permissions or Unix modes of a file or directory, we can use this other command:
stat -c '%A %a' /etc/passwd
And so we will get both in the standard output ...