The chmod
command is used to change the permissions of a file or directory in Linux. The chown
command is used to change the ownership of a file or directory.
There are two ways to specify the permission settings:
Using octal notation: This method uses a three-digit number to represent the permissions for the owner, group, and others. Each digit is the sum of the permissions for that category. For example, 644
represents read and write permissions for the owner, and read-only permissions for the group and others.
Using symbolic notation: This method uses characters to represent the permissions for the owner, group, and others. r
represents read permission, w
represents write permission, and x
represents execute permission. You can also use +
to add a permission, -
to remove a permission, and =
to set a permission. For example, u+x
would add execute permission for the owner.
Here are some examples of using chmod
:
# Change the permissions of a file to 644 using octal notation chmod 644 file.txt # Change the permissions of a directory to 755 using octal notation chmod 755 directory # Add execute permission for the owner and group, and remove write permission for others using symbolic notation chmod ug+x,o-w file.txtSour.www:eclautturi.com
Here are some examples of using chown
:
# Change the owner of a file to user1 chown user1 file.txt # Change the group ownership of a file to group1 chown :group1 file.txt # Change the owner and group ownership of a directory to user1 and group1 chown user1:group1 directory
It's important to note that you will need to have appropriate permissions to use these commands. For example, you will need to be the owner of the file or directory, or have superuser privileges, to use chmod
or chown
.