The file system GNU / Linux
GNU / Linux is based on UNIX file system, which has a tree structure. The point of origin is called root and is represented with the symbol /
Un sistema GNU / Linux puede ser instalado en una "única partición" o en múltiples particiones. Existiendo la partición especial para el intercambio con la memoria, la partición swap. Esta partición permite al sistema usar el disco cuando agota la memoria
Underneath the root (/), hang all the system directories. Really root hangs the system root partition that contains the basic files for the boot and operation of the system. The other partitions, we can establish hang of directories
It is possible to have in different partitions, user files, user applications, files, of variable length, temporary files. The multiple partitions allow us to better manage the system
We can create backup copies of all of the parts that interests us or limit the use of certain parts to a particular user. In this way we prevent the disk from filling up completely, as the only one that has write permission on the partition root is the administrator user
The type of partition most used in GNU / Linux systems is the ext2 or ext3. The units are not fixed, such as cd-rom, blu-disk, zip, pendrive, etc, hang on different directories with a descriptive name that refers to them, within the directory /mnt
The description of the properties of each partition is done in the file /etc/fstab
Name of files
A valid filename for the Linux kernel can contain any character except the characters ‘/’ (bar) or ‘\0’ (void)
Sin embargo no es prudente usar caracteres especiales usados por la shell (la línea de comandos) tales como ($, ", ‘, &, #, (, ), *, [, ], {, }, …). Tampoco debe empezar por el carácter ‘-‘ que puede ser confundido con una opción
When a user is created, the shell defines the default which will use the input directory named like the user name. The value of this directory entry can be found in the system variable $HOME
In each directory there are at least two accessible entrances, which are ‘.’ (reference to the current directory) and ‘..’ (a reference to the parent directory). In the $PATH variable stores the reference to the subdirectory current. If you want to run commands contained in the current directory, use the command
The ‘/’ character is used to separate the different levels of directories within the file name
When the file name begins ‘/’ then we are stating the full path name or the name of the absolute path. If on the other hand starts with ‘./’ or ‘../’, then we are indicating a name of the relative path, because we are using the subdirectory current where we are. The last part of the name after the last ‘/’ character is the name base name
The files that start with ‘.’ are not considered and therefore are considered to be hidden to the system, except that certain commands are directed. For example, to list a directory using the ls command, but starting with ‘.’ does not list them in the list despite being the files the same as the rest
The system identifies internally the files with a number, which is called the number of i-node. In the i-node are saved for different properties of the file such as:
- file type
- id of the owner
- id of the group owner
- number of links
- its size
- date of last access
- date of the last modification
- date of change of the number of i-node
- an array with the data blocks that holds the file
Types of files
- Regular: mere stores of information. Some contain executable code
- Directories: table that contains the numbers of i-nodes and the names of all the files contained in the within the directory
- Special files: can be a device of type character or block device. The handling of these files depends on the particular device
- Symbolic links: files that contain a pointer to another file that could be stored in a different filesystem
- Hard links: file which can be seen with different names within the file system (similar to aliases). That is to say, we can list them as if they were files identical but that share the same i-node. The information resides in one place and the changes made in a file also occur in the other equivalent. Links of this type do not work with file systems different, have to be of the same type. Not all file systems support hard links, as that is a concept very much tied to UNIX-like operating systems
The directory tree
The directories and files of the GNU / Linux systems are standardized in a document called the FSSTND. Among the various distributions of Linux we can find some differences
We will describe the main directories defined by the standard and what it contains:
- /bin: basic commands of the operating system
- /boot: boot files, including the file of the kernel that has the form vmlinuz-x.x. x x.x
- /dev: device files
- /etc: configuration files of the system
- /etc/X11: configuration files for the X Windows (libraries for the management of the graphical environment, like Windows)
- /home: directories of the users. By default the same name as the user name
- /initrd: directory for the boot process
- /lib: libraries necessary for the implementation of the resident programs in the directories /bin and /sbin
- /mnt: to mount the removable devices (Cd-Rom, Blu-Disk, Zip, pen drive, ...)
- /proc: houses special files for that, or collect information from the kernel, or the provide. The files generate the information when you view them
- /root: home directory of the super user administrator (has all permissions on the system)
- /sbin: contains executable files that can only be run by root root
- /tmp: are saved to temporary files
- /usr: files that can be shared throughout the system. It is the place in which you are installing the user applications. Contains directories such as /usr/bin, /usr/sbin, /usr/lib, /usr/man, /usr/X11R6, ...
- /usr/local: it is for the exclusive use of root, to the installation of particular software of the machine, the peripheral drivers
- /var: ficheros de longitud variable. Esto incluye los directorios y ficheros de "spool", datos de administración y registro, así como ficheros transitorios y temporales que no se guarden en el directorio /tmp
To move in the path of directories we use the cd command. For example, if we want to access the directory man, write in the command line cd /usr/man
File permissions
Files have many attributes in addition to its name. To see the more significant when we run the ls -l
Numeric notation for permissions
The permissions of the files are stored in binary format and can be referenced numerically. To do so is given the value 4 to the read permission, the value 2 to the write permission and 1 for the execute permission. Then summed the values for user owner, group, and user either, getting a three-digit number. Let's look at an example:
Other permissions
There are also permissions SUIG and SGID, that allow to identify when a program is executed by the owner of the file or the group of the file instead of the user that has launched. In general it is used when the root wants to give permission for execution of one of its programs to another user
Another permission is the sticky bit, or townhouse (bit sticky), it is for the process to stay in RAM memory while it runs. It uses little
The numerical values for the SUIG are 4, for the SGID is 2, and for the bit sticky is 1, added in front of the other 3 values of permissions. As well, we could give to our program, the permit 4751
Command for permissions
The command to change permissions is chmod, and supports numeric format or character format. In the character formatting is used u (user), g (group), o (other) and to (all) to indicate to whom they affect. The symbols + (for adding permissions), – (for removing permissions), = (set permission). Finally, r (read), w (write), x (execution) s t (bit sticky)
Permissions for the directories
To understand how the permissions applied to a directory it is necessary to imagine that a directory is a regular file that only contains a table that lists the files present in that directory. In each directory there are always a couple of entries that are ‘.’ (for the current directory) and ‘..’ for the parent directory. The permission of execution is understood as access
If a directory does not have read permission, it will prove impossible for any command, including ls, read your content
If a directory does not have execute permission, will not be able to cd to that directory, or any of the subdirectories that hang of it. This makes it impossible all the operations that use that directory as part of the road
If you do not have write permission may not be given high, low, or modifications in the table, that is to say, you can not delete files nor create new ones, or rename them
Finally, in a directory, the bit sticky is understood as that it is protected before the creation of the same file by different users, even if they have sufficient permissions. It is usually applied to the /tmp directory
Other related commands
- umask: sets the default permissions for creation of files
- chown: allows you to change the user owner of a file or several files
- chgrp: allows you to change the group owner of a file or several files
How to run UNIX commands
UNIX commands follow the following structure:
The standard input is usually a file or the keyboard. The standard output is usually the screen, and the output of the standard error is also the screen
The format of the command follows the structure:
- order: the name of the command
- -: the minus sign indicates that it is an option
- options: one or more characters of options
- arguments: are literal, taken as input parameters for the command
Redirection and connections
Both the outputs as a standard input you can redirect to a file or device (remember that from the point of view of the system all are files)
We may also pass the standard output of one command to the standard input of another, using the connection
For these operations we use the following metacharacters for the shell:
> | command >file directs the standard output to the file |
>> | command >>file appends standard output to file |
< | command <file extracted file to the standard input |
<<str | follows the standard input until the next str in the line |
p1¦p2 | connects the standard output of p1 to the standard input of p2 |
The connections give a great power to the system, as, although it is a command by itself, then a trivial task, when combined with others become the tools of general and useful. This allows us to easily create new commands and that the growth of the system is limited only by our ability of creation
Other metacharacters of the shell
* | matches any string of zero or more characters in the files |
? | matches any single character in the file |
[ccc] | match any single character from ccc in files, are valid ranges 0-9 or a-z |
; | p1;p2 when the command p1 runs the command p2 |
& | as ; but do not expect it to end p1 |
`...` | run command in ...; output replaces `...` |
(...) | run command ... in a subshell |
$1, $2, ... | we replace the arguments in a file of the shell |
$var | value of the variable var in the shell |
${var} | value of the shell variable var avoids confusion when concatenating with text |
\ \c | it literally takes the character c |
‘...’ | it takes ... literally |
"…" | se toma … literalmente después de interpretar $, ‘…’ y \ |
var=value | it assigns the value to the variable var |
p1&&p2 | p1&&p2 run p1if it succeeds, run p2 |
p1¦¦p2 | p1¦¦p2 run p1 if this is not accomplished, run p2 |
UNIX commands
We're not going to expose here is a list of UNIX commands, explaining their functionality.
In the first place because there are multiple pages dedicated to it, and in the second place by the system itself provides us with multiple aids on them
With the man command you can get help from any program or setup file, if we want to know how it works, it can call itself in the following way: man man
When we do not know the name of a command we can use the command apropos, and to indicate something related to it
Another help command is the info command. This command usually complete the help of man
Many commands give help among its options by running the command
Another source of help are the HOWTOs. Are tutorials on how to perform certain operations in the system. Are published by The linux documentation project (The Linux Documentation Project) and available in many languages
Some packages include own documentation in a subdirectory of /usr/share/doc that has the same name as the package
Note: do not forget that with the tab key, the shell completes the file names, which helps to locate the commands and files even if we don't remember his full name. In addition to avoid many errors when typing