Home Command line tools “-rw-r–r–“: Step by Step Explanation

“-rw-r–r–“: Step by Step Explanation

by The Linux Digest Guy

When you run the command “ls -l” you will be greated by these strings of characters that display the files permissions. At first these arbitrary combinations of dashes, letters, and hyphens may seem daunting to look at. But with a little knowledge, you can easily decipher them, with little more than a glance.

This particular combination, -rw-r–r–, is quite common and you will run into it quite often. Let’s just start with the simple explanation to start with.

What does the Linux permission -rw-r–r– mean?

By deciphering this permission string, we can tell that this is a regular file. The owner of the file has read and write permission, the owning group has only read permission and everyone else has read permission.

The file type field

The first character in the string is the file type string. In our example the value is represented by a dash. Which tells us it is just a regular file. Most files will have a dash in this file.

But there are other possible values. The ‘d’ for directory being probably the most common one. The ‘l’ for a symbolic link is also very common. There are several other special file types, but that is a little bit beyond the scope of this tutorial.

The three different groups

Each file permission string represents three different groups of users. Each group is represented by three characters.

  • The owner of the file. This is usually the user that created the file. But the owner can be changed afterwards. In this case the owner has the permission string “rw-“. Which means the owner can read the file and write to it. But the dash at the end means that the file is no executable.
  • The owning group of the file. This is also usually the group the files creator belongs to. But as before it can be changed afterwards. In this example the groups permission is represented by “r–“ which means that members of the group can only read the file.
  • Others. This is the permission that is applied to every user that is not a member of the owning group and is not the owner of the file. In our example, these users are represented by the “r–“ which means that they can only read the file. They can not write to it and cant run it as an executable file.

Possible values for each group

As I mentioned before, each group of users is represented by three characters. Each group of characters can typically have these values: “rwx”.

  • r: meaning read permission. This group can read the file. If this permission is missing, that effectively means that this group has no access to the file.
  • w: meaning write permission. This group can also write to the file. This is necessary to make any changes to the file. Regular files in a users home directory or configuration files will usually have this permission set.
  • x: meaning execute permission. A file that can be run as a program or script will need to have this permission set for users that need to run it. Otherwise it will need to be accessed by calling some other program.

The last value, “x” can be replaced by some other characters in special cases. Such as “t” for the sticky bit or “s” for setuid. But we will leave those edge cases to other tutorials.

Use the chmod command to change permissions

If your user has write permission to a file, you can change its permissions. To do that you would use the chmod command.

To change the permission of a file to the permissions in our example, “-rw-r–r–” we could call chmod in this way:

chmod u=rw,g=r,o=r name_of_file

-rw-r–r– in octal

You can also call chmod with an octal value of the permissions you want to set. This can be much quicker to type, if you know the value you want to set. To set the permission to -rw-r–r–:

chmod 0644 name_of_file

Conclusion

So, we’ve covered the basics of Linux file permissions using the example “-rw-r–r–.” We now know who can read the file, who can write to the file and if it is executable.

Knowing how file permissions work is super important if you want to keep your Linux system secure, stable, and user-friendly.

By understanding these concepts, you’ll be able to manage who can access files and folders, protect important data, make sure your system runs smoothly, and help users work together easily. Plus, this knowledge comes in handy when fixing file access problems or meeting legal rules.

As you keep using Linux, don’t forget to pay attention to file permissions and update them as needed. With a good understanding of file permissions, you can handle the Linux file system like a pro and get the most out of its awesome features.

Check out some of my other articles below if you want to learn more.

0

Related Posts

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More

Privacy & Cookies Policy