chmod is a command in Linux that allows you to change the permissions (or the access mode) 1
of a file, a director using either the symbolic or the numeric system. Note that only route or the 2
file’s owner, can change the file’s permissions. 3
Let’s take a look at the command’s general structure: 4
There's the command chmod [who][OPERATION][permissions] and the filename 5
Who signifies the user's category, whose permissions will be changed; some letters are used and some 6
possible ones are u for the user that owns the file, g for the group that the file belongs to and o 7
for the other users. 8
The OPERATION flags define whether the permissions are to be removed, added, or set: 9
a hyphen means remove the specified permissions; 10
the plus sign means Add the specified permissions and equals means 11
change the current permissions to the specified permissions. And the permissions are specified 12
using the letters r, w and x. 13
I'm going to show you a bunch of examples so you can deeply understand it. 14
As an non unprivileged user, I'm creating a new file. 15
And let's see the file's permissions. 16
These are default permissions of the newly created file. 17
And I am removing the file's permission for the owner; all other permissions remain unchanged. 18
so chmod the owner uses the symbol u; it comes from the word user, -w 19
and the name of the file. 20
The write permission of the owner was removed. 21
Now you see a hyphen instead. 22
I'm adding the read, write and execute permissions for the owner; the permission of the group and 23
others remain unchanged. 24
chmod u+rwx and the file, the owner has all permissions. 25
I'm removing the execute permission for the owner, u-x 26
I'm adding the write permission for the group, g+w, and I am removing all the permissions for the 27
others, so o-rwx and the file; if you want to be verbose or display a message for each 28
operation at the -v option after the commeand name. 29
Let's go ahead! 30
I'm removing the read permission for both the owner and the group: owner group -r I'm adding the 31
execute permission for the owner so,u+x and I'm removing all the permissions for the others. 32
,o-rwx and the file. 33
If you want to change a permission for all categories use the `a` letter. I'm adding read and removing 34
write and execute for all user classes. 35
The final permissions of the file will be read only for all user categories. 36
So chmod a+r,a-wx and the name of the file. 37
So we notice that plus is adding permissions and the - is removing permissions. 38
You can also change the current permissions to the specified permissions using the equal sign and the 39
required permissions:chmod ug owner and group = r w , o 40
so others= 41
And an empty space. 42
And the name of the file. This command will give the owner and the group the permissions to read and 43
write the file and the others will have no permissions at all. 44
The final permissions of the file will be: rw- - 45
rw- -- 46
Note that if no permissions are specified after the equal symbol, all permissions from the specified 47
user class are removed. 48
Sometimes it's easier to change the permissions using the numeric method. 49
This is also known as the absolute changing mode because you set the permissions for all three user 50
classes: owner, group and others at the same time. 51
Let's see some examples! 52
In the next example, I'll give to the file’s owner the read and write permissions and only the read permission 53
to the group and all the other users: chmod 644 and the file, I'm giving all permissions 54
to all categories of users. 55
And the last one I want the owner to have only to get permission and the group and the others to have 56
no permissions at all, so chmod 400 and the file. 57
To recursively operate on all files and directories under a given directory, use the capital art option, 58
I'm creating a new directory structure with some directories and files inside. 59
This is the new directory structure. 60
Let's see the permissions of all files and directories. 61
I'm using the capital R of ls to display the directory recursively. 62
And they see the premises and I want to change the permissions of all files and subdirectories under 63
the dir1 directory to 750 64
So chmod R 750 and the directory name dir1. 65
And I'm displaying the permissions of its contents again. 66
Note that such a command is not recommended, since the permissions of files have different effects 67
as the permissions of directories. In Linux a file does not have the same permissions as the directory. 68
And in the last example of this lecture, I'll show you how to set the file's permissions to be the same as 69
those of a specified reference file; for example, the following command will assign the permissions 70
of one file to another one. 71
I'm creating a new file. 72
OK, I've got a permission denied there, because probably the file already exists and it's owned 73
by root. 74
Let's check it. 75
OK, that's the file; I'm creating it under another name, I'll simply write i.txt. 76
This is the first file and this is the second. 77
And I want the user .txt to have the permissions of ii.txt; so chmod -- reference, the reference 78
file 79
i.txt and the file. 80
Let's see the files permissions. 81
Now they have the same permissions. 82
We'll take a break and we'll see in the next lecture what do the permissions of directories actually 83
mean. 84
See you in two seconds.