Permissions determine the ways different users can interact with a file or directory. When listing a file with the ls -l
command, the output includes permission information. For example if we will want to use a script file called hello.sh located in the Documents directory :
First we will have to switch into the Documents Directory using this example below for instance:
admin@localhost:~$ cd ~/Documents
Now since we are in the Documents directory we will have to use the ls -l
to view the permissions, the output will be something like the below example:
admin@localhost:~/Documents$ ls -l hello.sh
-rw-r--r-- 1 admin admin 647 Dec 20 2017 hello.sh
Now below we will look at a review of the fields relevant to permissions.
File Type Field
-
rw-r--r-- 1 admin admin 647 Dec 20 2017 hello.sh
The first character of this output indicates the type of a file.
if the first character is a
-
, this is a regular file. If the character was ad
, it would be a directory.
Permissions Field
-rw-r--r--
1 admin admin 647 Dec 20 2017 hello.sh
After the file type character, the permissions are displayed. The permissions are broken into three sets of three characters:
Owner
rw-
r--r--
The first set is for the user who owns the file. If your current account is the user owner of the file, then the first set of the three permissions will apply and the other permissions have no effect.
-rw-r--r-- 1 admin
admin 647 Dec 20 2017 hello.sh
The user who owns the file, and who these permissions apply to, can be determined by the user owner field:
Group
-rw-r--
r-- 1 admin admin 647 Dec 20 2017 hello.sh
The second set is for the group that owns the file. If your current account is not the user owner of the file and you are a member of the group that owns the file, then the group permissions will apply and the other permissions have no effect.
The group for this file can be determined by the group owner field:
-rw-r--r-- 1 admin admin
647 Dec 20 2017 hello.sh
Other
-rw-r--r--
1 admin admin 647 Dec 20 2017 hello.sh
The last set is for everyone else, any one who that first two sets of permissions do not apply to. If you are not the user who owns the file or a member of the group that owns the file, the third set of permissions applies to you.
Permission Types
here are three different permissions that can be placed on a file or directory: read, write, and execute.
- read(r) Allows for file contents to be read or copied.
- write(w) Allows for contents to be modified or overwritten. Allows for files to be added or removed from a directory.
- execute(x) Allows for a file to be run as a process, although script files require read permission, as well. > Understanding which permissions apply is an important skill set in Linux
If You have read this far I really appreciate, Help me to grow my community:
Connect With me at Twitter | Insta | YouTube | LinkedIn | GitHub
Do share your valuable opinion, I appreciate your honest feedback!
Check out my other Blogs too:
- Administrative Access Commands On Linux
- Why You Should Learn Linux
- Choosing The Right Python Framework for Web Development
- How To Get Started With Open Source Project Contribution
- Build A Random Name Generator Using Python
- How To Write A Good README File
- Top Freelancing Tool For Developers
- Top Apps To Learn Coding
- Coding A Jokes App Using Python
See you in my next Blog article, Be Safe and Take care!!
Enjoy Coding
Top comments (2)
I would suggest explaining the number system that directly correlates to the rwx that is related to permissions and the
chmod
command that goes with it as the numbers and command are what you will deal with the most.Good article with a good explanation, but I don't think you can explain one part of permissions without directly explaining one of the most important parts. But maybe this is a 2 part post?
Sure it's a 2 part post, here is the rest of the article: larymak.hashnode.dev/changing-file...