How do I use chmod to change permissions

How do I use chmod to change permissions

In this tutorial we will see about chmod command, so how do I use chmod to change permissions in Linux?

There are three basic modes to files and directories: readable, writable, and executable. Additionally, each of these modes can be applied to the user, a group, or everybody.

“user” means you, the person who owns the file. “other” means everyone else on the machine. “group” is a list of people you can specify. If you want to create your own special group of users, follow the instructions in the answers article ” Using ‘setgrp’ and ‘chgrp’ to share files with a group of users”.

You can determine the modes on files by executing the command “ls -l”. The leftmost field for each file will contain the information for the modes.

The 10 characters in the first field refer to the following characteristics:

Character    What it means
        1               "d" if a directory, "-" if a file
        2               "r" if file is readable to user, "-" if not
        3               "w" if file is writable to user, "-" if not
        4               "x" if file is executable to user, "-" if not
        5-7             same as 2-4, with reference to group
        8-10            same as 2-4, with reference to everyone on eniac

As an example:

 example% ls -lg
   total 28
   -rw-r--r--  1 user       group     273 Mar 24 11:28 file1
   -rwxrwxrwx  1 user       group    1449 Jan 29 14:01 file2
   -rwx------  1 user       group    4119 Jan 26 13:22 file3

file1 is readable and writable to the user, and readable to everyone on eniac. file2 is readable, writable, and executable by everyone. file3 is readable, writable, and executable only to the user.

To change the permissions of a file, one uses the “chmod” command, with the following syntax:

example% chmod [who][op][permissions] filename

“who” refers to the users that have a particular permission: the user (“u”), the group (“g”), or other users (“o”, also known as “world”). “op” determines whether to add (“+”), remove (“-“) or explicitly set (“=”) the particular permissions. “permissions” are whether the file should be readable (“r”), writable (“w”), or executable (“x”). As an example:

example% chmod u+x file1

will add executable permission for the user to file1.

example% chmod o-w file2

will remove write permission for others for file2.

example% chmod ugo=rx file3

will explicitly make file3 readable and executable to everyone. Note that you can combine the “who” and “permissions” fields to allow multiple values.

For more information on changing permissions, use the “man chmod” command.

Enjoyed this video?
How do I use chmod to change permissions
"No Thanks. Please Close This Box!"