- Each linux file has a set of properties that control access to it.
- Collectively these properties are know as the file's access mode or mode.
- Access modes can be manipulated using either octal or symbolic formats.
The access mode consists of four sets of three flags.
in octal these flags are represented as 4 digits i.e. 0644
- the first digit '0' represents any special attributes that are set
- the second '6' the file owner's permissions
- the third '4' the file group permissions
- the fourth '4' the file world, everybody and everything's permissions
often, when no special attributes are set i.e. the first digit is '0', the first digit is omitted when reporting the mode i.e. 644 => 0644
in symbolic form these flags are represented as 9 characters i.e. rw-r---r--
- the first three characters represent 'rw-' represent the owner's permissions
- the next three 'r--' the group permissions
- and lastly 'r--' the world permissions
- 'r' = read, 'w' = write, 'x' = execute and '-' = none permissions set
|111||read, write, execute||7||rwx|
Display a file's access mode in symbolic form
$ ls -al perm-change.txt -rw-r--r-- 1 mark mark 0 Dec 13 00:29 perm-change.txt
One character appears in front of the access mode, in this case a '-'. This character identifies the type of file.
|b||Block special filec|Character special file|
|p||Pipe special file|
Putting it all together
perm-change.txt is a regular file with, no special attributes set, read and write permissions for the owner (mark), read permissions for members of group (mark) and read permissions for everything else. This mode equates to '0644' in octal.
Display a file's access mode in both symbolic form and in octal
$ stat perm-change.txt | grep "Access: (" Access: (0644/-rw-r--r--) Uid: ( 1000/ mark) Gid: ( 1000/ mark) (or) $ stat -c "%a %A %F %n" perm-change.txt 644 -rw-r--r-- regular empty file perm-change.txt (or) $ stat --printf "%a %A %F %n\n" perm-change.txt 644 -rw-r--r-- regular empty file perm-change.txt
The last two forms of the stat command omit the the first octal digit. When it is missing it has a value of '0'.