How to use chmod command on Ubuntu Linux with examples

|

|

The chmod command in Ubuntu Linux is used to define or change permissions on files, limiting access to certain users. Its syntax involves specifying options, mode, and the file to be modified. Different modes can be set for users, group members, and others, with read, write, and execute permissions represented numerically. The command offers options…

The chmod command defines or changes permissions or modes on files and limits access to only those allowed access.

The chmod command on Ubuntu Linux defines or changes permissions or modes on files and limits access to only those allowed access. It is used to modify the access permissions of a file or directory.

Using the chmod command, you can specify who can read, write, and execute files. This is particularly useful when working with files with sensitive information or files that need to be executed by certain users.

For example, you may want to limit access to a file so only certain users or groups can read, write, or execute it. The chmod command makes this possible.

Overall, the chmod command is a powerful tool that allows you to control access to files and directories on Ubuntu Linux.

About the chmod command:

The chmod command defines or changes permissions or modes on files and limits access to only those 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 the same as using your mouse to right-click a file or folder, selecting 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 syntax options can be reordered. But a straight format must be followed.,.

Below is an example syntax of how to use the chmod command.

chmod [OPTION]. MODE[,MODE]. FILE.

or

chmod [OPTION]. OCTAL-MODE FILE.

Options:

The command line options are switches or flags that determine 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 for 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 a 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, –quietUse them -for –silent or –quiet option to suppress most error messages
-R, –recursiveUse the -R or –recursive option to change files and directories recursively
–helpUse the –version option to display this help and exit
 –versionUse 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 own a file called Confidential and want to change the permissions or modes so that users 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 the 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 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.

sudo chmod 754 Confidential

The digit 7 is equal, read, write, and execute. The digit 5 is similar to read and execute, and the digit 4 is equivalent to read.

  • 4 = Read
  • 2 = Write
  • 1 = Execute
  • 0 = no permission

So, 7 = 4 + 2 + 1 (rwx);      5 = 4  + 1 (RX);   4 (r)

Configure access to a file so only the user can read, write, and execute, and the group/others can read and 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!

I hope you like it, and please come back soon for more Ubuntu Linux commands!


Discover more from Geek Rewind

Subscribe to get the latest posts to your email.

Like this:



2 responses to “How to use chmod command on Ubuntu Linux with examples”

  1. David R Webber Avatar
    David R Webber

    I think you should have sudo chmod – not sudo by itself!

  2. Nurul Atikah Japry Avatar
    Nurul Atikah Japry

    I just want to say your note saves my day. Thank you.

Leave a Reply

Discover more from Geek Rewind

Subscribe now to keep reading and get access to the full archive.

Continue reading