What does the long listing of files mean?
Let’s breakdown the ls output.
- The first column gives the type of the file (e.g. directory or ordinary file) and the file permissions. We’ll cover file permissions in the section below.
- The second column is the number of links to the file.
- The third column shows the owner of the file. In our example, all the files are owned by the user sde.
- The fourth column shows the group of users to which the file belongs.
- The fifth column is the size of the file (in our example it’s shown in human readable format).
- The next three columns show the time when the file was last changed (for a directory, this is the time when a file in that directory was last created or deleted).
- The final column is the name of the file.
File permissions provide a way of controlling who can read and modify files.
Let’s look at the file permission for the file Licence.txt.
-rw-rw-r-- 1 sde sde 1.1K Jun 21 14:24 Licence.txt
As we explained in the first section the first character indicates the file type. Here it’s a – because License.txt is an ordinary file.
The next nine characters fall into three sets of three characters, indicating permissions for owner, group, and other.
- r = readable
- w = writeable
- x = executable (for files) or accessible (for directories)
For the Licence.txt file, sde (the user who owns the file) has the access rights
rw- means that he can read and write the file but not execute it (as it’s a plain text file). Any user in the group sde has the same permissions. Everyone else has the access rights of
r--, meaning they can read the file but not write or execute it.
chmod (change mode) utility
The chmod (change mode) utility allows us to add or remove permissions. There are two types of syntax, the simpler “character” syntax and the numeric “octal” syntax. We’ll describe the simpler “character” syntax.
Here’s some examples of modifying permissions for the file email.cpp
-rwxrwxr-x 1 sde sde 4.4K Jun 21 14:27 email.cpp
chmod g-w email.cpp – this command removes write permission for group.
chmod go-rwx email.cpp – this command removes read, write, and execute permission for group and others.
chmod o+w email.cpp – this command adds write permission for others.
All articles in this series: