linux chmod command usage in explanation
- 2021-01-06 00:53:21
chmod command syntax
Here's the correct syntax for using the chmod command:
chmod [options] mode [ . mode] file1 [file2 ...]
Here are some common options used by chmod:
-f, -silent, -quiet (suppress most error messages)
●-v, -verbose (Output diagnostic information for each processed file)
●-c, -changes (similar to detailed but only reported when making changes)
●-R, -recursive (Recursive changes to files and directories)
●--help (show help and exit)
●--version (output version information and exit)
Below is a list of several numeric permissions that can be set for users, groups, and everyone else on the computer. Next to numbers are read/write/perform letter equivalents.
●7: Represents rwx, with read, write, and execute permissions
●6: rw-, has read and write privileges
●5: Represents rx, with read and execute permissions
●4: means r--, has read-only permission
●3: Represents -wx, with write and execute permissions
●2: Represents -w-, with write only permission
●1: Represents -x, with execution permissions only
●0: Represents --, no permission
Note: If you want to list file permissions, you need to use the ls command.
Example chmod command
If the user wants to change the permissions on the file "participants" so that everyone has full access to the file, enter the following command:
chmod 777 participants
Description: The first 7 sets the permissions of the user, the second 7 sets the permissions of the group, and the third 7 sets the permissions of the other owner.
If the user wants to be the only one who can access it, use the following command:
chmod 700 participants
Users who want to provide full access to themselves and their team members can use the following command:
chmod 770 participants
If users want to keep full access for themselves, but want to prevent others from modifying files, they can use the following command:
chmod 755 participants
The following uses the above letters to change the permissions of the file "participants" so that the owner can read and write the file, but not change the permissions of anyone else:
chmod u=rw participants
Set the mode
Use the chmod command to set other file system modes for files and directories. For example, to set the sticky bit - which means that only the file owner, directory owner, or superuser can delete the file, regardless of the file's read-write group permissions - add 1 to the sequence of numbers:
chmod 1755 participants
Users can also use the chgrp command to change the group ownership of existing files and folders, and the newgrp command to change the default group of new files and folders.
Keep in mind that symbolic links used in the chmod command affect the real target object.