How to change Permission of a folder or file in linux
ReportUse the ‘chmod’ command with the desired permission code and the folder name. For example, to give the owner of the folder read, write, and execute permissions, and give everyone else only read and execute permissions, you could use the following command:
chmod 750 foldername
In this example, the permission code 750
corresponds to the following permissions:
7
: The owner of the folder has read, write, and execute permissions.5
: Users in the group that the folder belongs to have read and execute permissions.0
: All other users have no permissions.
When Linux file permissions are represented by numbers, it’s called numeric mode. In numeric mode, a three-digit value represents specific file permissions (for example, 744.) These are called octal values. The first digit is for owner permissions, the second digit is for group permissions, and the third is for other users. Each permission has a numeric value assigned to it:
r (read):
4w (write):
2x (execute):
1
In the permission value 744
, the first digit corresponds to the user, the second digit to the group, and the third digit to others. By adding up the value of each user classification, you can find the file permissions.
For example, a file might have read, write, and execute permissions for its owner, and only read permission for all other users. That looks like this:
- Owner:
rwx = 4+2+1
=7
- Group:
r-- = 4+0+0
=4
- Others:
r-- = 4+0+0
=4
The results produce the three-digit value 744
What do Linux file permissions actually do?
I’ve talked about how to view file permissions, who they apply to, and how to read what permissions are enabled or disabled. But what do these permissions actually do in practice?
Read (r)
Read permission is used to access the file’s contents. You can use a tool like cat or less on the file to display the file contents. You could also use a text editor like Vi or view on the file to display the contents of the file. Read permission is required to make copies of a file, because you need to access the file’s contents to make a duplicate of it.
Write (w)
Write permission allows you to modify or change the contents of a file. Write permission also allows you to use the redirect or append operators in the shell (> or >>) to change the contents of a file. Without write permission, changes to the file’s contents are not permitted.
Execute (x)
Execute permission allows you to execute the contents of a file. Typically, executables would be things like commands or compiled binary applications. However, execute permission also allows someone to run Bash shell scripts, Python programs, and a variety of interpreted languages.
Thread Reply
Please briefly explain why you feel this answer should be reported .
Report CancelHow to change the rights of the file or folder