Linux-Mandrake:
User Guide and
Reference Manual

MandrakeSoft

 
 
January 2000
http://www.linux-mandrake.com


Next : Using KDE
Previous : Introduction
Up

(Back to the table of contents)

Chapter 1 : Basic Unix concepts


The name "Unix" will maybe say something to some of you. You may even use a Unix system at work, in which case this chapter won't be of much help to you.

For those of you who have never used it, reading this chapter is abolutely necessary. The knowledge of concepts which will be introduced here answers a surprisingly high amount of questions commonly asked by beginners in the Linux world. Similarly, it's likely that some of these concepts can answer most of the problems you may encounter in the future.

Users and groups

The concept of users and groups is extremely important, for it has a direct influence on all other concepts that this chapter will introduce.

Linux is a true multi-user system, so in order to use your Linux machine you must have an account on it. When you created a user at installation time you had, in fact, created a user account. You may remember you were prompted for the following items:

The two important parameters here are the login name (commonly abbreviated by login) and the password. These are what you will use in order to connect to the system.

Another action which occurred when creating a user account is the creation of a group. By default, the installation program will have created one group per user. As we will see later, groups are useful when you have to share files between several people. A group can therefore hold as many users as you wish, and it's very common to see such a separation in large systems. For example: In a university you can have one group per department, another group for teachers, and so on. The reverse is also true: a user can be member of one or more groups. A math teacher, for example, can be a member of the teachers group and also be in the group of his beloved math students.

All this does not say how you can log in. Here it comes.

If you have chosen to have the graphical interface upon bootup, your startup screen will look similar to figure 8.1.

Graphical mode login session
Figure 8.1 Graphical mode login session

In order to log in, you must enter your login name into the Login: text field, then enter your password into the password field. Note that you'll have to type your password blindly: there will be no echo into the text field.

If you are in console mode, your screen will look similar to figure 4.2.

Console mode login session
Figure 4.2 Console mode login session

You will then have to enter your login name at the Login: prompt and press Return, after which the login program (called, surprise surprise, login) will display a Password: prompt, and you will obey by typing the password for this account -- always blindly!

Note that you can log in several times with the same account, on additional consoles and under X. Each session that you open is independent, and it's even possible to have several X sessions. By default, Linux-Mandrake has six virtual consoles in addition to the one reserved to the graphical interface. You can switch to any of them by typing the key sequence Ctrl-Alt-F<n>, where <n> is the number of the console which you want to switch to. In general, the graphical interface is on console number 7.

In addition to the creation of user accounts, you will also have noticed that during the install, DrakX (or the program you used) will have prompted you for the password of a very special user: root. This user is special for a simple reason: it's the account normally held by the system administrator which will most likely be you. For your system's security, it is very important that the root account always be protected by a good password.

If you regularly login as root it is very easy to make a mistake which can render your system unusable; only one mistake can do it. In particular, if you have not created a password for the root account any user can alter any part of your system. This is obviously not a very good idea.

It is worth mentioning that internally, the system does not identify you with your login name but with a unique number assigned to this login name: the user ID (UID for short). Similarly, every group is identified by its group ID (GID) and not its name.

File basics

Files are another topic where Linux differs greatly from Windows and most other operating systems. We will cover the most obvious differences here, for more info see Chapter 14.0 in the Reference manual which offers greater detail.

The first difference, and probably the most important, is related to the presence of users. We could have mentioned that every user has their own directory (called his home directory), but this doesn't say what really goes on, which is that each file on a Unix system, is the exclusive property of one user and one group. Therefore, not only does a user have his own home directory, but he's also the owner of his files in the real sense of the word.

Moreover, permissions are associated to each file which only the owner can change. These permissions distinguish three categories of users: the owner of the file, every user who is a member of the group associated to the file (also called the owner group) but who is not the owner, and others, which means every user who is neither the owner nor member of the owner group. There are three different permissions:

Every combination of these permissions is possible. For example: You can allow only yourself to read the file and forbid it to all other users, and forbid every other use of the file. You can even do the opposite, even if it's not very logical at a first glance :) As the file owner, you can also change the owner group (if and only if you are a member of the new group), and even deprive yourself of the file (that is, change its owner). Of course, if you deprive yourself of the file you will lose all your rights to it...

Let's take the example of a file and a directory. The display below represents entering the ls -l command from a command line:

$ ls -l
total 1
-rw-r-----   1 francis  users           0 Jul  8 14:11 a_file
drwxr-xr--   2 gael     users        1024 Jul  8 14:11 a_directory/
$

The results of the ls -l command are (from left to right):

Let's now look closely at the permissions associated to each of these files: first of all, we must strip off the first character representing the type, and for the file a_file we get the following rights: rw-r-----. The interpretation of these permissions is as follows:

For the directory a_directory, the rights are rwxr-xr--, and as such:

Remember, there is one exception to this rule. The root account can change the attributes (permissions, owner and group owner) of all files, even if he's not the owner. Which means that he can also grant himself the ownership. He can read files on which he has no read permission, traverse directories which he normally has no access to, and so on. And if he lacks a permission, he just has to help himself...

In conclusion, we will mention a final distinction regarding filenames. They are indeed much less limited than under Windows:

Processes

A process defines an instance of a program being executed and its environment. As for files, here we will only mention the most important differences, and you will want to refer to the Reference manual for a more in-depth discussion on this subject.

The most important difference is, once again, directly related to the concept of users: each process is executed with the rights of the user who launched it. Therefore, if we get back to the example of the file a_file mentioned above, a process launched by the user gael will be able to open this file in read-only mode, but not in read-write mode, as the rights associated to the file forbid it. Once again, the exception to the rule is root...

You will have guessed from the above discussion that one of the parameters of a process' environment is the UID and GID of the user who has launched it. This allows for the system to know whether what the process is asking for is "legal" or permitted.

One consequence is that Linux is mostly immune to viruses. In order to operate, viruses need to infect executable files. As a user, you don't have access to vulnerable system files so the risk is greatly reduced. Add to this that viruses are very rare in the Unix world in general. So far there have been only three known viruses for Linux, and they were completely harmless when launched by a normal user. Only one user can damage a system by activating these viruses, and once again, it's... root!

Interestingly, anti-virus software does exist for Linux, but for DOS/Windows files... The reason for it being that, more and more, you will see Linux file servers serving Windows machines with the help of the Samba software package (see chapter 30.0 in the Reference manual).

Internally, the system identifies processes in a unique way by, once again, a number. This number is called the process ID, or PID. Moreover, all processes can receive signals which is how you can control them (well, only the processes that you have launched, not another user's process, the exception to this rule being again who you know...): you can stop a process, kill it if it's causing you trouble and so on. In a following chapter, you will learn how to track down a PID and send signals to it. This is useful to terminate and suspend problem processes.

Small introduction to the command line

The command line is the most direct way to send commands to the machine. If you use the Linux command line, you'll soon find that it is much more powerful and capable than command prompts you may have previously used. The Linux command line offers direct access to thousands of utilities which don't have graphical equivalents. The reason for it is that you have a direct access, not only to all X applications, but also to thousands of utilities in console mode (as opposed to graphical mode) which don't have their graphical equivalent, or the many options and possible combinations of which will never be showable in the form of buttons or menus.

But, admittedly, it requires a little help to get started. This is what this chapter is for. The first thing to do, if you're using KDE, is to launch a terminal emulator. You have an icon which clearly identifies it in the panel (figure 4.3).

The terminal icon in the KDE panel
Figure 4.3 The terminal icon in the KDE panel

What you have got in this terminal emulator when you launch it is actually a shell. This is the name of the program which you interact with. You find yourself in front of the prompt:

[joe@localhost] ~ $

This supposes that your username is joe and that your machine name is localhost (which is the case if your machine is not part of an existing network). All what appears after the prompt is what you will have to type. Note that when you are root, the $ of the prompt turns into a #. (All these are only true in the default configuration, since you can customize all the details). The command to "become" root when you have launched a shell as a user is su:

# Enter the root password; it will not appear on the screen
[joe@localhost] ~ $ su
Password:
# exit will make you come back to your normal user account
[root@localhost] joe # exit
[joe@localhost] ~ $

Anywhere else in the book, the prompt will be symbolically represented by a $, whether you be a normal user or root. You will be told when you have to be root, so remember su :) A # in the beginning of a code line will represent a comment.

When you launch a shell for the first time you normally find yourself in your home directory. To display the directory you are currently in, type the command pwd (which stands for Print Working Directory):

$ pwd
/home/joe

There are a few basic commands which we are now going to see, and you will soon find you cannot do without them.

cd: Change Directory

The cd command is just like the one of DOS, with a few extras. It does just what its acronym says, change the working directory. You can use . and .., which stand respectively for the current directory and its parent directory. Typing cd alone will bring you back to your home directory. Typing cd - will bring you back to the latest directory you were in. And lastly, you can specify the home directory of a user john by typing  john (' ' on its own or followed by '/' means your own home directory). Note that as a normal user, you normally cannot go into other people's personal directories (unless he explicitly authorized it or this is the default configuration on the system), except if you're... root, so let's be root and practice:

$ pwd
/root
$ cd /usr/doc/HOWTO
$ pwd
/usr/doc/HOWTO
$ cd ../FAQ
$ pwd
/usr/doc/FAQ
$ cd ../../lib
$ pwd
/usr/lib
$ cd ~joe
$ pwd
/home/joe
$ cd
$ pwd
/root

Now, become a normal user again :)

Some environment variables and the echo command

Processes have their environment variables and the shell allows you to view them directly, with the echo command. Some interesting variables are:

To have the shell print the value of a variable, you must put a $ in front of its name. Here, echo will help you:

$ echo Hello
Hello
$ echo $HOME
/home/joe
$ echo $USERNAME
joe
$ echo Hello $USERNAME
Hello joe
$ cd /usr
$ pwd
/usr
$ cd $HOME
$ pwd
/home/joe

As you can see, the shell substitutes the value of the variable before it executes the command. Otherwise, our cd $HOME would not have worked here. In fact, the shell has first replaced $HOME by its value, /home/joe, therefore the line became cd /home/joe, which is what we wanted. It is the same for echo $USERNAME and so on.

cat: print the contents of one or more files to the screen

Nothing much to say, this command does just that: print the contents of one or more files to the screen:

$ cat /etc/fstab
/dev/hda5 / ext2 defaults 1 1
/dev/hda6 /home ext2 defaults 1 2
/dev/hda7 swap swap defaults 0 0
/dev/hda8 /usr ext2 defaults 1 2
/dev/fd0 /mnt/floppy auto sync,user,noauto,nosuid,nodev 0 0
none /proc proc defaults 0 0
none /dev/pts devpts mode=0620 0 0
/dev/cdrom /mnt/cdrom auto user,noauto,nosuid,exec,nodev,ro 0 0
$ cd /etc
$ cat conf.modules shells
alias parport_lowlevel parport_pc
pre-install plip modprobe parport_pc ; echo 7 > /proc/parport/0/irq
#pre-install pcmcia_core /etc/rc.d/init.d/pcmcia start
#alias car-major-14 sound
alias sound esssolo1
keep
/bin/zsh
/bin/bash
/bin/sh
/bin/tcsh
/bin/csh
/bin/ash
/bin/bsh
/usr/bin/zsh

less: a pager

Its name is a play on words related to the first pager ever under Unix, which was called more. A pager is a program which allows a user to view long files page-by-page (more accurately, screen-by-screen). We speak about less rather than more because its use is much more intuitive. Use less to view large files, which do not fit on a screen. For example:

less /usr/doc/HOWTO/PCMCIA-HOWTO

To navigate the file, just use the up and down arrow keys. Use 'q' to quit. less can do far more than that, indeed: just type h for help, and look. But anyway, the goal of this section is just to enable you to read long files, and this goal is now achieved :)

ls: listing files (LiSt)

This command is equivalent to dir in DOS, but it can do much much more. In fact, this is largely due to the fact that files can do more too :) The command syntax for ls is as follows:

ls [options] [file|directory] [file|directory...]

If no file or directory is specified on the command line, ls will print the list of files in the current directory. Its options are very numerous and we will only cite a few of them:

Some examples:

Useful keyboard shortcuts

Many keystrokes are available which can save much typing and this section will present some of the most useful ones. This section assumes you are using the default shell provided with Linux-Mandrake, Bash, but these keystrokes should work with other shells too. In this section, C-<x> means Ctrl+<x> (hold down Ctrl key, press key <x>, release both keys).

First: the arrow keys. Bash maintains a history of previous commands which you can view with the up and down arrow keys. You can scroll up to a number of lines defined in the 'HISTSIZE' environment variable. Moreover, the history is persistent from one session to another so you will not lose the commands you have typed in a previous session.

The left and right arrow keys move the cursor left and right in the current line, so you can edit your lines this way. But there is more to editing: C-a and C-e, for example, will bring you respectively to the beginning and to the end of current line. The Backspace and Del keys will work as expected. An equivalent to Backspace is C-h and an equivalent to Del is C-d. C-k will delete all the line from the position of the cursor to the end of line, and C-w will delete the word before the cursor.

Typing C-d on a blank line will make you close the current session, which is much shorter than having to type exit. C-c will interrupt the currently running command, except if you were in the process of editing, in which case it will cancel the editing and get you back to the prompt. C-l clears the screen.

Finally, there is the case of C-s and C-q: these keystrokes respectively suspend and restore the flow of characters on a terminal. They are very seldom used, but it may happen however that you type C-s by mistake. So, if you strike keys but you don't see any character appearing on the terminal, try C-q first and beware: all characters you have typed between the unwanted C-s and C-q will be printed to the screen all at once.


Next : Using KDE
Previous : Introduction
Up

Copyright © 2000 MandrakeSoft