Archive for the ‘4 - File characteristics’ Category

IV – File characteristics

onsdag, juni 23rd, 2010

Unlike in real life in a linux system you cannot do exactly what you want. See, you might have to have some kind of permission in order to read, write and execute a file. It’s like being five years old again when mother told me I could not do crack but just meth. Not that I did care but anyway. When running ‘ls -l‘ you’re able to see all files listed in the folder. But together with the ‘-l’ parameter you also get some additional parameters – the characteristics of each file.

ls -l
# drwxr-xr-x 1 sgar users 0 May 5 16:22 my_folder

In today’s class we’re looking at what we’re allowed to do with each file so we notice the first string of hieroglyphs in the example above – ‘drwxr-xr-x’. For educational purposes, after all that’s why you’re here, we split it into ‘d   rwx   r-x   r-x’.

# d   rwx   r-x   r-x 1 sgar users 0 May 5 16:22 my_folder
First thing we can notice is the first ‘d’ character. The ‘d’ stands for ‘directory’. So we come to the conclusion that this is a folder, not a file (technically this is a file but it serves as a directory. Also, careful readers might have noticed that a symbolic link begins with an ‘l’ from the ‘Links’ chapter.).

# d   rwx   r-x   r-x 1 sgar users 0 May 5 16:22 my_folder
The next three characters (rwx) represents the owners rights. They are spelled out in
the magic language ‘r’, ‘w’ and ‘x’.

r‘ stands for read rights. When set for a directory, this permission grants the ability to read the names of files in the directory (but not to find out any further information about them such as contents, file type, size, ownership, permissions, etc.)

w‘ stands for write rights (puh!) so that you’re able to modify a file. In the case of a directory, this permission grants the ability to modify entries in the directory. This includes creating files, deleting files, and renaming files.

x‘ stands for execution rights. This permission must be set for executable binaries (for example, a compiled c++ program) or shell scripts (for example, a Perl program) in order to allow the operating system to run them. When set for a directory, this permission grants the ability to traverse its tree in order to access files or subdirectories, but not see files inside the directory (unless read is set).

# d   rwx   r-x   r-x 1 sgar users 0 May 5 16:22 my_folder
The owner is the person, monkey or regular drug dealer that created the file – in our case ’sgar’ is the owner which is listed together with the ‘ls -l’ cmd.

# d   rwx   r-x   r-x 1 sgar users 0 May 5 16:22
my_folder
The next three characters ‘r’, ‘-’ and ‘x’ are the group rights. Everybody belongs to a group. In the example above the group is named ‘users’ and everyone belonging to this group have rights to read and execute the file or, in our case, the directory.

# d   rwx   r-x   r-x 1 sgar users 0 May 5 16:22
my_folder
Last and truly least are the ‘others’ rights – the rights for everybody that hasn’t created the file or belong to the correct group. In the example they as well are allowed to read and to execute the file but not write to it.

Every file and directory have such rights. Our next chapter will focus on how to change them. After all, breaking rules are much more fun. I hated cigarettes until I saw my first ‘no smoking’ sign. ‘Keep of the grass’, let’s play soccer.