The wise say, "Everything in Linux is a file". Well, you will be somehow amazed how this paradigm works in Unix/Linux. It is really the fact that, everything in Linux is a file. Your hard drive as a whole is a single file, with the proper drivers, every partition of them is a single file, and every directory is a file that contains files. Every process is a file, and every network socket is a file. A webcam is also a file. That does not only make the lives of the programmers easier, but it makes the system really stable since the file abstraction layer lies in the heart of the Linux kernel which is one of the oldest parts written in any GNU/Linux operating system. That also makes the system more secure. For example in any standard Linux operating system, the file /etc/shadow (which contains the user names and an indicator of what the password is) is readable or writable only by the super user (which is the only user that has all privileges on the computer). Let's settle this fact early enough: the super user can do any doable thing on the computer. He can change the privileges of any other user, he can change the file owner of any file, and he can handle any critical system file. A malicious application running by the super user is usually the last thing you want on your computer because it can cause serious damage to it. That is why the normal users work with less privileges, and deciding the legitimate actions that a user can do are abstracted by setting the correct file permissions.
A user may read, write or execute a file. Once a user creates a file he becomes the file owner (unless the super user decided otherwise). The file owner (along with the super user) is the one entitled by changing this file permissions. Users are divided into groups, and therefore comes the fact that every file has owner permissions / group permissions / everybody else's permission. The chmod command changes the file permissions. One easy way to make it work is the chmod by the Nubmers way.
chmod xyz /path/to/file/file_name
x, y, and z are octal numbers. i.e.: 0 <= x, y, z <= 7.
x: represents the owner permissions.
y: represents the group permissions.
z: represents everybody else's permissions.
To put the correct value of x, y, or z follow this rule: 0 means no permissions, add 4 to give the read permission, add 2 to give the write permission, and add 1 to give the execute permission. For example:
chmod 754 file
This command gives read / write / execute permission to the file owner, read / execute to the file owner's group, and the read permission to anyone else.
That one good post. Did you try to post a series of articles about Linux file systems? e.g. procfs and /dev files like random and urandom? I think it will better clarify your fascination of how Linux handles everything as a file and may serve as a simplified introduction to such file systems
ReplyDelete