How to use the chmod command on Linux

How to use the chmod command on Linux

The chmod command changes file and folder access permissions. The chmod command, like any other command, can be executed from the command line or through a script file.

If you need to list a file’s permissions, use the ls command.

Syntactic commands

This is the correct syntax when using the chmod command:

chmod [options] mode[,mode] file1 [file2 ...]

The following are the options that are commonly used with chmod:

-f, –silent, –quiet: Suppresses most error messages.
-v, –verbose: Displays diagnostics for each file processed.
-c, –changes: Liked verbose but only reported when changes were made.
-R, –recursive: Change files and directories recursively.
–help: Displays help and exits.
– version: Output version information and exit.

Below is a list of numerical permissions that can be set for users, groups, and everyone on the computer. Next to the number are letters that are read, written, and executed.

7, rwx: Read, write and run.
6, rw-: Read and write.
5, r-x: Read and run.
4, r–: Read-only.
3, -wx: Write and run.
2, -w-: Just write it.
1, –x: Just run.
0, —: Nothing.

Example Commands

To change participant file permissions so that everyone has full access to it, enter:

chmod 777 participants

The first 7 sets permissions for users, 7 the second sets permissions for groups, and 7 the third sets permissions for everyone.

If you want to be the only one who can access it, use:

chmod 700 participants

To give yourself and members of your full access group, enter:

chmod 770 participants

If you want to maintain full access for yourself, but want others not to modify the file, use:

chmod 755 participants

The following uses letters from above to change participant permissions so that the owner can read and write to the file, but not change the permission for others:

chmod u=rw participants

More information about the chmod command

Change group ownership of existing files and folders with the chgrp command. Change the default group for new files and folders with new commands.

The symbolic links used in the chmod command affect the target object.

Mode Settings

Use chmod to set additional file system modes for files and directories. For example, to set sticky bits, start 1 in number sequence:

chmod 1755 participants

With a little stickiness, only the file owner, directory owner, or root superuser can delete files, regardless of file read-write group permissions.

Related posts

How To Remove Snap From Ubuntu


How to compile the ONLYOFFICE Document Server from source code on Ubuntu


How to Install Nginx with PHP and MySQL (LEMP Stack) on Ubuntu 20.04 LTS


How to use the classic Unity Desktop on Ubuntu 20.04


How to Install Django on Ubuntu 20.04 LTS


How to Install phpMyAdmin with Nginx and Let’s Encrypt SSL on Ubuntu 20.04 LTS


How to Count Files in Directories on Linux


How to Install and Use PHP Composer on Ubuntu 20.04


How to Install Steam on Ubuntu 20.04