Data Scientist or Machine Learning programmer must have faced the error messages like you cannot install something or cannot start something due to restrictions or permission. They are not allowed to do some operation on the file and folders they want to access. Therefore it becomes very important for them to understand the concepts of permission on Linux. In this tutorial on “ how to, “ you will know how to change Permissions in Linux. I am using Ubuntu Linux terminal for demonstrating all the commands. You can apply these commands on any Linux operating system.
How to Read the Permission of Files or Folders?
Before changing the permission you must know how to read the permission in Linux. Suppose you have a folder named “ AI” (short form of Artificial Intelligence). Type the command ls -l to display the folder AI in details. You can see there is a word written like this drwxrwxrwx. The “d” alphabet tell that it is directory and rwxrwxrwx represents file permission of the AI folder. The sequence represents three groups first rwx for the user that owns the file second rwx for the group that owns the file and third rwx for the user that is not in the group. The rwx stand for read(Can see but cannot modify), write(modify but not read) and execute (Run the file) for executing scripts or programs.
How to Change the Permission of the File or Folder?
You can change the permission of the file using chmod (Change File mode Bit ) command. There are two ways you can change the permission of the file. One is octal notation like 777,755,644 e.t.c and the other is the symbolic notation like a=r,g+w,o-x. You will learn both of them.
You must have seen in hosting provider or cloud server some octal notation values like 755, 777 e.t.c, This is the permission given to the file. The first digit represents permission for user, second Group and third for the other user. Each Read, Write and Execute have values 4,2 and 1 respectively. For example 754 it means User Total values is 4 (Read) + 2(Write) +1 (Execute) that is 7 . For group 4 (Read) + 0(Write) +Execute (1) = 5 and for others 4(Read) + 0(Write) + 0(Execute) that is 4. Thus 7 -For the user, 5 for Group and 4 for the other 754.
Symbolic Notation to change the permission
This is the easiest and approachable way of representing permission. The + sign add permission, – removes permission and = add permission and removes others. Generally, for the user, the symbolic notation is u+rwx,(add permission to read, write and execute) for the group it is g=r (add read permission but not to write and execute ) and for the others, it is o-rwx ( remove read, write and execute permission). You can simply write a for all.
Let’s understand with a simple example.
Suppose you have script lets name it demo.sh. Inside the script echo “Hello! Data Science Learner ” is written. When you try to run it, it will not run if the execute permission is not given. Therefore you have to give execute permission by typing a+x and this will give execute permission to demo.sh for all users and groups. When you run the script you will get the output ” Hello! Data Science Learner”. You can also add or remove persimmon according to the above table.
Adding permissions to the files or folders using the Symbolic Notation is the best way. It allows you to remember easily how to remove or add permission for the read, write and execute. Octal Notation is also good but you will always have to calculate to find the number that you mostly doesn’t want.
Hope you have learned How to Change Permissions in Linux in a very simple way. If you have any suggestion and queries then contact us on our data science learner page for quicker reply.
View What others are Reading:
Join our list
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.