How to Use the chmod Command on Linux-Basic Linux Permission|linux file permission|wiz maverick
Control who can access files, search directories, and run scripts using the Linux’s chmod command. This command modifies Linux file permissions, which look complicated at first glance but are actually pretty simple once you know how they work.
On each line, the first character identifies the type of entry that is being listed. If it is a dash (-) it is a file. If it is the letter d it is a directory.
The next nine characters represent the settings for the three sets of permissions.
–The first three characters show the permissions for the user who owns the file (user permissions).
–The middle three characters show the permissions for members of the file’s group (group permissions).
–The last three characters show the permissions for anyone not in the first two categories (other permissions).
The letters represent:
r: Read permissions. The file can be opened, and its content viewed.
w: Write permissions. The file can be edited, modified, and deleted.
x: Execute permissions. If the file is a script or a program, it can be run (executed).
To use chmod to set permissions, we need to tell it:
Who: Who we are setting permissions for.
What: What change are we making? Are we adding or removing the permission?
Which: Which of the permissions are we setting?
We use indicators to represent these values, and form short “permissions statements” such as u+x, where “u” means ” user” (who), “+” means add (what), and “x” means the execute permission (which).
The “who” values we can use are:
u: User, meaning the owner of the file.
g: Group, meaning members of the group the file belongs to.
o: Others, meaning people not governed by the u and g permissions.
a: All, meaning all of the above.
If none of these are used, chmod behaves as if “a” had been used.
The “what” values we can use are:
–: Minus sign. Removes the permission.
+: Plus sign. Grants the permission. The permission is added to the existing permissions. If you want to have this permission and only this permission set, use the = option, described below.
=: Equals sign. Set a permission and remove others.
The “which ” values we can use are:
r: The read permission.
w: The write permission.
x: The execute permission.
###Give the members of the group permission to read the file, but not to write and execute it:
chmod g=r filename
###Remove the execute permission for all users:
chmod a-x filename
####Repulsively remove the write permission for other users:
chmod -R o-w dirname
###Remove the read, write, and execute permission for all users except the file’s owner:
chmod og-rwx filename
###The same thing can be also accomplished by using the following form:
chmod og= filename
###Give read, write and execute permission to the file’s owner, read permissions to the file’s group and no permissions to all other users:
chmod u=rwx,g=r,o= filename
###Add the file’s owner permissions to the permissions that the members of the file’s group have:
chmod g+u filename
##################################################
The main fact is you have to remember the followings:
-rw-rw-r– 1 test test 0 Sep 8 17:37 bourne
user group
the first “-” meaning file type.
1) ‘-‘ means text file
2) ‘d’ means folder file/directory
3) ‘c’ means character file
4) ‘b’ means block file
r=4
w=2
x=1
################################################
#chmod
#linux command
#centos7
#linux permissions
#permission
linux foundation