In previous lessons, we have used the command ls to review the permissions assigned to a file.
Whenever you use the -l flag with ls, you get some extra information. You can see what ls is doing by looking at the man page (i.e. man ls), but here is a quick breakdown.
$ ls -l hello_world -rw-r--r-- 1 fileowner filegroupname 62 Jul 16 12:32 hello_world
What does this cryptic output mean? Here is a breakdown of the fields in the order they are given.
|File Mode||Number of links||Owner||Group||Size||Last Modified||File Name|
|Example||-rw-r--r--||1||fileowner||filegroup||62||Jul 16 12:32||hello_world|
|Description||entry type “-” (regular file) owner permissions “rw-”, group permissions “r--” other permissions “r--”||Number of hard links to this file||owner||group||bytes||date||name|
Here is another cryptic convention. It is a string representation meant to pack a lot of information into symbols.
The first dash - represents the entry type. It can be one of b,c,d,l,s,p,- but we will only interact with - (regular file) d (directory) and l (symbolic link).
The other entries are special file types that are read and written differently than normal files. They are used by linux to do complex things, like connect to devices such as the hard drive.
Three characters each, these strings represent the permissions set for that given party. Each group of three characters has a numeric representation.
|Three Character string||Numeric representation||File Permission||Remark|
|---||0||Not readable, not writeable, not executable.||(rarely used)|
|r--||4||Read-only||Often a default setting|
|r-x||5||Read/Execute||Common for executables.|
|rw-||6||Read/Write||Common for documents.|
|rwx||7||Read/Write/Execute||Used for your own scripts.|
Notice how we used
$ chmod 755 hello_world
on the script we wrote? Those numbers are broken down by the table above for owner (7 - Read/Write/Execute), group (5 - Read/Execute) and other (5 - Read/Execute).
There other ways to tell chmod what to do. To see them, do
$ man chmod