Let's move ahead and talk about the effect of the permissions on directories. As you'll notice, the 1
permissions on directories have a completely different effect as the permissions on files. 2
I'm going straight to the point with an example. 3
I'm creating a new directory with a file and another directory inside it, so mkdir Linux and Ubuntu, 4
I'LL the -p option because I want to create the directories simultaneously. 5
and let's say, who -a > linux/users.txt 6
I'll sett only the read permission on the directory. 7
So chmod 8
4oo and the directory name Linux 9
Let's see its permissions! ls-ld and the name of the directory. 10
I have used the d option to see information about the directory and not about its contents. 11
So the Linux directory has only the read permission set for the owner and the user I'm logged in as 12
is the owner; let's try to list the contents of the directory. 13
And surprise! 14
We see the name the file and the directory that resides within my directory, but some errors and 15
strange question marks as well. 16
I’m moving into the directory using cd. 17
And I can't, I am not allowed to enter the directory. 18
I'm trying to remove a file from the directory. 19
rm -rf linux and the file. As I'm the owner of the file 20
I should be able to remove it. 21
But surprise, I'm not allowed. 22
So the read permission on a directory only means that the directory is contents can be shown by running ls. 23
It doesn't give you access to the contents of the directory. 24
That's why I couldn't remove the file or move into the directory. 25
I don't have access to the directorie's contents. 26
Imagine the directory as a glass box where you can see what's inside it, but you cannot touch it. 27
Now, if it read means showing the directory's contents, why did I get that error when I was running at 28
ls-l 29
When you run ls -l the command tries to access the contents to see the type, permissions, 30
owner and so on; and it's not allowed. The ls command was not allowed to read the contents of metadata, 31
hence that error. And when you run ls with no options, 32
you run in fact an alias which is ls --color=auto. 33
The --color option tries to identify the file’s type to display its name and color based on its type. 34
type. 35
For example, you see directories in blue and regular files in black, and that was not allowed. 36
This option was the problem. 37
If instead of the alias I run the original ls command, and not the alias, by writing a 38
\ before its name, then I’ll get no error: 39
\ls and the directory name; note that you can rename the directory, 40
that being allowed is you have the required permissions on its parent. 41
I'm renaming it back. 42
Let's add the write permission for the owner. 43
chmod 600 and the directories name. 44
Now, the owner has both read and write permissions. 45
And I'll try to do the same as before. 46
ls -ld linux ls linux; I can see the name of the files in the subdirectories, but 47
no other information. 48
cd linux; I can't enter the directory. 49
rm linux users.txt 50
And I cannot remove or create files in the directory. 51
At first sight, it seems that the write permission didn't change a thing, and that's exactly so. 52
If the execute permission is not set, the write permission has no effect. 53
But if you set both write and execute write means that the directory's contents can be modified, 54
create new files 55
or subdirectories, rename or delete existing files or subdirectories. 56
So as a conclusion the write permission has effect only along with the execute permission; and finally, 57
the execute permission on a directory means access to that directory's contacts. 58
I can move into the directory using cd 59
I can remove or create new files. 60
So chmod 700 and the directories name. 61
Now I can do anything ! 62
ls linux; ls -d linux 63
I can enter the directory. 64
I can remove files or create other files. 65
I have a total control on that directory. 66
At the end, I have a question for you: what will happen if a directory has all the permissions for 67
a user's class but a ffile inside it has no permissions at all? 68
Could, for example, a user from that class remove the file? 69
Let's test it. 70
So the Linux directory has all the permissions for the owner. 71
But the file inside the directory will have no permissions at all. 72
So chmod 000 linux a.txt the user has no permissions on a. txt and I'm trying 73
to delete the file rm linux 74
a.txt 75
It says that's a write protected regular file, but I continue and try to remove it. 76
And the file was removed. 77
We noticed that the user had no problem removing the file, even though the file's permissions didn't 78
allow that. 79
So the permissions of the parent directory were more important than the file,s permissions. Keep 80
this in mind!