File Permissions in Linux
1. chmod
(Change Mode)
The chmod
command allows you to modify file permissions.
These permissions control read, write, and execute access for the
owner, group, and others. Here are two ways to use chmod
:
-
Symbolic Mode:
- Syntax:
chmod [ugoa] [[+-=] [mode]] file
- Example: To add write permission for the user, group, and others to a file named
file1
, use:chmod ugo+w file1
- Syntax:
-
Numeric Mode:
- The mode is a combination of three digits:
- First digit: User permissions
- Second digit: Group permissions
- Third digit: Others’ permissions
- Example: To give read/write/execute permission to the user,
read/execute permission to the group, and execute permission to others,
use:
chmod 751 file1
- The mode is a combination of three digits:
2. chown
(Change Ownership)
The chown
command changes the ownership of a file. Only the current owner can change ownership. Syntax:
chown [owner] [file]
Example: To change the owner of file1
to user2
, assuming it’s currently owned by the current user:
chown user2 file1
3. chgrp
(Change Group Ownership)
The chgrp
command changes the group ownership of a file. Like chown
, only the owner can perform this action. Syntax:
chgrp [group] [file]
Example: To change the group of file1
to group2
, assuming it’s currently owned by the current user:
chgrp group2 file1
Understanding these commands will empower you to manage permissions effectively. Happy learning!
No comments:
Post a Comment