While using Linux, you may encounter the error, “permission denied”. This error occurs when the user does not have the privileges to make edits to a file. Root has access to all files and folders and can make any edits. Other users, however, may not be allowed to make such edits.
Remember that only root or users with Sudo privileges can change permissions for files and folders.
The permissions can be changed using the chmod
keyword. The syntax for the command is:
chmod flags permissions filename
flags
are the additional options users can set.permissions
define if the user can read, write, or execute the file. They can be represented using symbolic or octal numbers.filename
is the name of the file whose permissions are changed.Here is an example where users can read, write, and execute a file; whereas, group and others can only read it.
chmod u=rwx,g=r,o=r file
Here, each letter has a meaning:
r gives read permissions
w gives write permissions
x gives execute permissions
The same command can be run using octal notation:
chmod 744 file
Here, each digit represents the sum of the permissions allowed:
4 gives read permissions
2 gives write permissions
1 gives execute permissions
0 gives no permissions
The sum of these permissions is used to represent each type of author.
The following flags can be set:
Now, let's resolve this issue in the below terminal. click the following terminal and change the file mode by passing the chmod +x example_script.sh
and then again execute the file by using ./example_script.sh
.
Note: We have used a file
example_script.sh
that only have read permission. So we can read it but we can't excute the file but we can read its content. So we need to update its permission to get access.
Free Resources
Copyright ©2024 Educative, Inc. All rights reserved.