Linux: Managing file permissions

Part 1: Understanding permissions

From the image, the first column of asd corresponds to user/owner of the file or directory. The second column of asd corresponds to the group the file or directory belongs to, in this case it belongs to the group asd.

How do we know if it is a file or directory in Linux?

Directories start with a d followed by rwx or - - - combinations

Files contain a - in the beginning, followed by rwx or - - - combinations

Sometimes it may start with l which means it's a link. A link is just a reference to the file or directory.

This string is called the permission string. It gives us information about a different set of permissions set of different users and groups.

What are the three types of file permissions in Linux?

There are three types of file permissions in Linux:

  • Read [r]: Allows a user or group to read(view) a file.

  • Write [w]: Allows a user or group to edit a file.

  • Execute [x]: Allows a user or group to execute a file.

What are the three types of directory permissions in Linux?

There are three types of directory permissions in Linux:

  • Read [r]: Allows a user to be able to see contents in the directory (allows ls command).

  • Write [w]: Allows a user to be able to change the contents in the directory.

  • Execute [x]: Allows a user to be able to enter into the directory (allows cd command).

What does ls -l layout?

As you can see in the image above, showing what each set of strings means when you use ls -l to display information about the files and directories in the current folder in a long format.


Part 2: Changing permissions

In Linux, you can change the permissions of a file/directory by using the chmod command.

The permissions on a file/directory can be represented by a 3-digit octal number or a combination of letters, each representing the read, write and execute permissions for the owner, group and others.

To change the permissions of a file using the octal notation, we use the following command which sets read, write and execute for the user. Read only for the group and others.

chmod 744 textfile.txt

Now to do the same using the symbolic mode or with a combination of letters, here's how we do it:

chmod u+rwx textfile.txt
chmod go+r textfile.txt

u: user | g: group | o: other

u+rwx: set read, write and executable permissions for the user.

go+r: sets read-only permission for the group and others.


Thank you so much for reading my blog. Finally, I would like to thank DevBytes for sponsoring this blog.

DevBytes is a must-have app/extension if you're a developer or learning to code, this is a place for you. Stay updated with the latest news in the developer field and grow your career.

DevBytes selects the latest news from authentic sources, tech blogs, and the influencer community and summarises them in less than 64 words. Check out their Android app (100k+ downloads) ⤵️

https://devbytes.co.in/

or use the browser extension.⤵️

https://chrome.google.com/webstore/detail/devbytes-tech-and-ai-news/hplbpdkajdhlggncdpdmnkjldopmoomg

Also follow their WhatsApp channel for hilarious and relatable coding memes, inside jokes, and tech humour. ⤵️
https://whatsapp.com/channel/0029Va53jMg1noz0BoMimo1n


11
Subscribe to my newsletter

Read articles from Mohammed Asadullah Sayeed directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Mohammed Asadullah Sayeed
Mohammed Asadullah Sayeed

I am a CS Student from India.