The chmod command is used to define or change permissions or modes on files and limit access to only those who are allowed access.
If you’re a new user or student and want to learn how to use and manage Linux systems, the easiest place to start might be on Ubuntu Linux OS.
Ubuntu is an open-source Linux operating systems that runs on desktops, laptops, server and other devices.
When you’re ready to learn how to use the chmod commands, follow the guide below:
About chmod command:
The chmod command is used to define or change permissions or modes on files and limit access to only those who are allowed access. It changes the mode of each FILE to MODE.
The chmod command stands for change mode. and it’s used to limit access to resources.
It’s a same as using your mouse to right-click a file or folder and selecting the permission tabs and defining who can access the resource. the chmod command is the way to do it on the command line.
Syntax:
The syntax is the rule and format of how the chmod command can be used. the systax options can be reordered. but a straight format must be followed.,.
Below is an example syntax of how to use the chmod comamnd.
chmod [OPTION]. MODE[,MODE]. FILE.
or
chmod [OPTION]. OCTAL-MODE FILE.
Options:
The command line options are switches or flags that determined how the commands are executed or controlled. they modify the behavior of the commands. they are separated by spaces and followed after the commands.
Below are some options of the chmod command:
FILE. | Replace FILE.. with the file you want to change its permissions |
MODE, OCTAL-MODE |
Replace the MODE (rwx) or OCTAL-MODE (777) with value to change the permission to |
-c, –changes | Use the -c or –changes option to show verbose but report only when a change is made |
-f, –silent, –quiet | Use the -f or –silent or –quiet option to suppress most error messages |
-R, –recursiven | Use the -R or –recursiven option to change files and directories recursively |
–helpn | Use the –version option to display this help and exit |
–version | Use the –version option to output version information and exit |
Examples:
Below are some examples of how to run and use the chmod on Ubuntu Linux.
If you’re a owner of a file called Confidential and want to change the permisions or modes so that user can read / write and execute, group members can read and execute only and others can only read, you will run the commands below.
sudo chmod u=rwx,g=rx,o=r Confidential
The commands above change the permission of the file called Confidential so that user can read (r), write (w)and execute (x) it. group members can only read (r) and execute (x) and others can only read (x) its content.
The same command above can be written as shown below using its octal permission notation.
sudo chmod 754 Confidential
If you’re not logged in as a root account, you may have to use the sudo command it it.
sudo chmod 754 Confidential
The digit 7 is equl, read, write and execute. the digit 5 is equal, read and execute, the digit 4 is equal read.
- 4 = Read
- 2 = Write
- 1 = Execute
- 0 = no permission
So, 7 = 4 + 2 + 1 (rwx); 5 = 4 + 1 (rx); 4 (r)
To configure access to a file so only the user can read, write and execute and group / others can read, run the commands below.
sudo 744 Confidential
The commands below change the permissions of the Confidential file so that everyone has full access. read/write/execute
sudo 777 Confidential
When you run chmod with the –help option, you’ll see the help text below:
Usage: chmod [OPTION]. MODE[,MODE]. FILE. or: chmod [OPTION]. OCTAL-MODE FILE. or: chmod [OPTION]. --reference=RFILE FILE. Change the mode of each FILE to MODE. With --reference, change the mode of each FILE to that of RFILE.
That’s it!
Hope you like it and please come back soon for more Ubuntu Linux command!