I heard from a guy who recently started with Linux that when he wants to see file permissions in Linux in the octal format…because he is not to clear with permissions in human-friendly format…he open FileZilla, then do right click on file – Properties….and that is a way how he see permissions in octal format. Why octal? Because he is not familiar with chmod in human-friendly format.

This ‘show me permissions in ocal format’ is usually needed when user want to copy permissions from one file (folder, link…) to another, but he is not familiar with chmod in human friendly format (know only chmod 600 file). Except standard chmod 755 you can use chmod u=rwx,g=rx,o=rx. For example 777 is the same as a=rwx where parameter ‘a’ mean all, and ‘rwx’ mean read-write-execute. In example ‘chmod u=rwx,g=rx,o=rx’ – parameter ‘u’ mean user, ‘g’ mean group and ‘о’ mean others. Parameter ‘=’ mean ‘give me this privileges and overwrite all what is current’, ‘-‘ mean remove (u-w will remove write privilege from user) and + mean…give/append next permissions (g+x will give execute permission to group)

Here’s an example of copying permissions between files, where you have only fuman-friendly format and don’t know for octal.

 

For privilege listing in octal format, we will use command ‘stat’ which is part of coreutils package. Syntax in bellow

stat -c 'SOME FORMAT' filename

For format, if you want only to list permissions in octal format, next parameters can be interesting for you:

  • %a – Show me a permissions in octal format
  • %A – Show me a permissions in human-friendly format (like in ls -l)
  • %n – Show me file name

…so for listing in this case – we can use next command: stat -c ‘%a %A %n’ testfajl*

Other interesting parameters for stat:

  • %F – Show me a file type (regular file, empty file, directory, symlink…)
  • %U – Show me a username of file owner
  • %G – Show me a owner group
  • %x – Show me last access date
  • %w – Show me when was file created
  • %y – Show me when was last modification time
  • Other characters for easier print and formatting, without % (like –>, ->, |, name, whatever)

Here is a more ‘advanced’ listing

So now, you can list file permissions in octal format and to use your usual chmod XXX command.