In this part, I go over changing permissions of files and folders.
1.COMMAND:
chmod
DESCRIPTION:
change file mode bits
SYNOPSIS:
chmod [OPTION] [ugoa][+-=][rwx] FILE
OPTION:
-R recursive, include objects in subdirectories
u user the owner of the file
g groupusers who are members of the file's group
o othersusers who are neiter the owner of the file nor members of the file's group
a allall three of the above, same as ugo
+ adds the specified modes to the specified classes
- removes the specified modes from the specified classes
= the modes specified are to be made the exact modes for the specified classes
r read read a file or list a directory's contents
w writewrite to a file or directory
x executeexecute a file or recurse a directory tree
Example:
piniheaven@fish:~/Documents/tutorial$ ls -l
total 0
-rw-rw-r-- 1 jack piniheaven 0 Aug 25 21:42 essay.txt
piniheaven@fish:~/Documents/tutorial$ sudo chmod u+x essay.txt #give user the permission to execute essay.txt
[sudo] password for piniheaven:
piniheaven@fish:~/Documents/tutorial$ ls -l
total 0
-rwxrw-r-- 1 jack piniheaven 0 Aug 25 21:42 essay.txt
piniheaven@fish:~/Documents/tutorial$ sudo chmodu-r essay.txt #remove user's permission of reading essay.txt
piniheaven@fish:~/Documents/tutorial$ ls -l
total 0
--wxrw-r-- 1 jack piniheaven 0 Aug 25 21:42 essay.txt
piniheaven@fish:~/Documents/tutorial$ sudochmod uo+r essay.txt#give user and others the permission of reading essay.txt
piniheaven@fish:~/Documents/tutorial$ ls -l
total 0
-rwxrw-r-- 1 jack piniheaven 0 Aug 25 21:42 essay.txt
piniheaven@fish:~/Documents/tutorial$ sudo chmod a=x essay.txt #assign user,group and others only the permission to execute essay.txt
piniheaven@fish:~/Documents/tutorial$ ls -l
total 0
---x--x--x 1 jack piniheaven 0 Aug 25 21:42 essay.txt
piniheaven@fish:~/Documents/tutorial$sudo chmod ugo+rwx essay.txt #assign user,group and others with the permission of read,write and excute
piniheaven@fish:~/Documents/tutorial$ ls -l
total 0
-rwxrwxrwx 1 jack piniheaven 0 Aug 25 21:42 essay.txt
piniheaven@fish:~/Documents/tutorial$ cd ..
piniheaven@fish:~/Documents$sudo chmod -R a=rx tutorial #assign user,group and others with the permission of read and excute, including it's subdirectories
piniheaven@fish:~/Documents$ ls -l
total 32
drwxrwxr-x 4 piniheaven piniheaven 4096 Aug 22 12:16 assemble
......
......
dr-xr-xr-x 2 jack piniheaven 4096 Aug 25 21:42 tutorial
piniheaven@fish:~/Documents$ ls -l tutorial/
total 0
-r-xr-xr-x 1 jack piniheaven 0 Aug 25 21:42 essay.txt
1.COMMAND:
chmod
DESCRIPTION:
change file mode bits
SYNOPSIS:
chmod [OPTION] [ugoa][+-=][rwx] FILE
OPTION:
-R recursive, include objects in subdirectories
u user the owner of the file
g groupusers who are members of the file's group
o othersusers who are neiter the owner of the file nor members of the file's group
a allall three of the above, same as ugo
+ adds the specified modes to the specified classes
- removes the specified modes from the specified classes
= the modes specified are to be made the exact modes for the specified classes
r read read a file or list a directory's contents
w writewrite to a file or directory
x executeexecute a file or recurse a directory tree
If you have any problem in reading following example,maybe you need to know more about file permission.Want more information?You can click my previous tutorial File Permission
Example:
piniheaven@fish:~/Documents/tutorial$ ls -l
total 0
-rw-rw-r-- 1 jack piniheaven 0 Aug 25 21:42 essay.txt
piniheaven@fish:~/Documents/tutorial$ sudo chmod u+x essay.txt #give user the permission to execute essay.txt
[sudo] password for piniheaven:
piniheaven@fish:~/Documents/tutorial$ ls -l
total 0
-rwxrw-r-- 1 jack piniheaven 0 Aug 25 21:42 essay.txt
piniheaven@fish:~/Documents/tutorial$ sudo chmodu-r essay.txt #remove user's permission of reading essay.txt
piniheaven@fish:~/Documents/tutorial$ ls -l
total 0
--wxrw-r-- 1 jack piniheaven 0 Aug 25 21:42 essay.txt
piniheaven@fish:~/Documents/tutorial$ sudochmod uo+r essay.txt#give user and others the permission of reading essay.txt
piniheaven@fish:~/Documents/tutorial$ ls -l
total 0
-rwxrw-r-- 1 jack piniheaven 0 Aug 25 21:42 essay.txt
piniheaven@fish:~/Documents/tutorial$ sudo chmod a=x essay.txt #assign user,group and others only the permission to execute essay.txt
piniheaven@fish:~/Documents/tutorial$ ls -l
total 0
---x--x--x 1 jack piniheaven 0 Aug 25 21:42 essay.txt
piniheaven@fish:~/Documents/tutorial$sudo chmod ugo+rwx essay.txt #assign user,group and others with the permission of read,write and excute
piniheaven@fish:~/Documents/tutorial$ ls -l
total 0
-rwxrwxrwx 1 jack piniheaven 0 Aug 25 21:42 essay.txt
piniheaven@fish:~/Documents/tutorial$ cd ..
piniheaven@fish:~/Documents$sudo chmod -R a=rx tutorial #assign user,group and others with the permission of read and excute, including it's subdirectories
piniheaven@fish:~/Documents$ ls -l
total 32
drwxrwxr-x 4 piniheaven piniheaven 4096 Aug 22 12:16 assemble
......
......
dr-xr-xr-x 2 jack piniheaven 4096 Aug 25 21:42 tutorial
piniheaven@fish:~/Documents$ ls -l tutorial/
total 0
-r-xr-xr-x 1 jack piniheaven 0 Aug 25 21:42 essay.txt