Linux is a multi-user system, allowing many users on the same machine at once. Due to security considerations, normal users are limited to manipulating only their personal files. Sometimes, however, it is needed to administer the system, to install software or perform maintenence tasks. To perform these tasks, a linux system has a special user account called root.
Using the root account could be very dangerous. One short command might wipe out your entire hard drive without warning. Therefore, you must observe extreme caution while working as root, avoiding root as much as possible.
To switch to the root account, open a console and type su(short for "Switch User" or "Super User"). You are now required to type the root password which you have set during system installation.
[alon@localhost alon]$ su
Password:
[root@localhost alon]#
Notice the hash sign (#) which usually signifies root mode.
In the linux world software comes in three main formats:
Most modern distributions are based on RPM packages. In an RPM-based system, it is preferred to install software via RPM, if available. Note, however, that the package you are installing should match your distribution. To find packages for your distribution, use rpmfind.net which lets you search for packages based on package name, or a file included in the package.
The RPM system is designed to make software work correctly by the use of dependancies. RPM automatically detects and reports conflicts, asking you to download and install additional packages to satisfy package dependancies.
To install a package, issue the command rpm -Uvh packagename.rpm, for example:
[root@localhost alon]# rpm -Uvh foobar-1.0-3mdk.i586.rpm
Preparing... ########################################### [100%]
1:foobar ########################################### [100%]
[root@localhost alon]#
On a Mandrake system, you can check and satisfy dependancies by using urpmi - the Mandrake package tool. To install, simply type urpmi packagename, for example:
[root@localhost alon]# urpmi locales-ru
Please insert the medium named "disc 1 Download Edition Installation CD (x86)
(cdrom1)" on device [/dev/scsi/host0/bus0/target0/lun0/cd]
Press Enter when it's done...
installing /mnt/cdrom/Mandrake/RPMS/locales-ru-2.3.1.2-8mdk.i586.rpm
Preparing... ##################################################
locales-ru ##################################################
[root@localhost alon]#
To uninstall, use rpm -e packagename. For example:
[root@localhost alon]# rpm -e locales-ru
[root@localhost alon]#
Some software is available only as source code, and sometimes use of source code is preferred. The source is usuall in C or C++, compressed in an archive. In Linux, two compressors are commonly used: gzip and bzip2, and the files are combined together using tar. To open a tar.gz or tgz archive, use the command: tar -xzvf file.tar.gz. To open a tar.bz2 archive, use tar -xjvf file.tar.bz2.
The archive will usually include a directory by the same name. In this directory you will usually find a README file, read it! There might also be an INSTALL file, read it too. Take a look at other files with capitalized names as well.
Most of these programs are based on a system called autoconf, which simplifies the compilation of Linux software. To install an autoconf-based program, do the following (as a normal user):
[alon@localhost foobar-1.0]$ ./configure
(... lots of output ...)
[alon@localhost foobar-1.0]$ make
(... lots of output ...)
[alon@localhost foobar-1.0]$ su
Password:
[root@localhost foobar-1.0]# make install
(... lots of output ...)
[root@localhost foobar-1.0]# exit
[alon@localhost foobar-1.0]$
The UNIX directory tree is structured based on the type of use of the files. A typical UNIX setup includes the following directories under the root directory (/):
| Directory | Contents |
|---|---|
| /bin |
Essential executables, used by all users |
| /boot |
Files needed to start the system, including the kernel |
| /dev |
Interfaces to system hardware (devices) |
| /etc |
Configuration files of all software and the system
itself |
| /home |
Users' home directories, which include personal files |
| /lib |
Essential libraries and kernel modules (drivers) |
| /mnt |
Mount-points of foreign filesystems (see below) |
| /opt |
Optional files and programs (usually empty) |
| /proc |
Interface to the kernel and running processes |
| /root |
Home directory of the root user |
| /sbin |
Essential system executables for use mostly by root |
| /tmp |
Temporary files, writable by all users |
| /usr |
All non-essential programs and program data |
| /var |
Variable system files, such as logs, mail, and print
jobs |
The /usr directory is again structured based on use, as follows:
| Directory | Contents |
|---|---|
| /usr/bin |
Executables of installed software |
| /usr/doc |
Documentation, see also /usr/share/doc |
| /usr/games |
Executables of games |
| /usr/include |
C/C++ header files for installed libraries |
| /usr/lib |
Installed libraries and other application files |
| /usr/local |
Locally installed software (from source, not rpm) |
| /usr/man |
Manual pages for the man command |
| /usr/sbin |
Executables of installed system software for use mostly by root |
| /usr/share |
Shared program data, such as graphics and documentation
|
| /usr/src |
Sources. Usually includes the source of the kernel. |
| /usr/X11R6 |
Files related to the X Windowing system (GUI) |
In UNIX, as opposed to windows, there is only one directory tree, starting from the root directory (/). The root directory is mapped (or mounted) to some disk partition. Other partitions may be mounted instead of any existing directory in the filesystem. Mounts may be used to seperate system directories to different disks, or to access foreign (Windows, floppy, CDROM, ...) filesystems. Foreign filesystems are usually mounted under /mnt.
The default mount locations of partitions are defined in a file called /etc/fstab (filesystem table). The file looks like this:
/dev/hda8 / reiserfs notail 1 1
none /dev/pts devpts mode=0620 0 0
none /dev/shm tmpfs defaults 0 0
/dev/cdrom /mnt/cdrom auto user,umask=0,exec,ro,noauto 0 0
/dev/fd0 /mnt/floppy auto user,umask=0,sync,exec,noauto 0 0
/dev/hda1 /mnt/win_c vfat defaults 0 0
/dev/hda5 /mnt/win_d vfat defaults 0 0
none /proc proc defaults 0 0
none /tmp tmpfs defaults 0 0
/dev/hda6 /usr ext3 defaults 1 2
/dev/hda7 swap swap defaults 0 0
The first column is the device (or partition) to mount, or none for special filesystems. /dev/hda is the first physical harddisk, and the number is the partition number. To find out your partition list and manipulate partitions use cfdisk or fdisk as root. WARNING: fdisk is a dangerous command and should be used with extreme caution.
The second column is the mount point, the location in the directory tree where the mounted filesystem starts. swap is a partition used for virtual memory.
The third column is the filesystem type, or auto which results in autodetection.
The fourth column is for mount options. For more information on these options and the meaning of the next columns see the man pages for mount andfstab.
In Linux, you can manipulate filesystem mounts in runtime. This is useful for mounting removeable storage such as CDROM and floppy. Note that you must unmount a filesystem before ejecting the removable media, or data loss will occur.
The current status of mounts is kept in /etc/mtab and /proc/mounts, and can be seen by running mount with no parameters. The format of these files is similar to /etc/fstab.
To mount a filesystem in /etc/fstab type (as root): mount mountpoint. To unmount, type umount mountpoint. For example to access the CD-ROM:
[root@localhost alon]# mount /mnt/cdrom # Mount the CD-ROM and lock the drive
[root@localhost alon]# ls /mnt/cdrom # List files on CD-ROM
Mandrake/
[root@localhost alon]# umount /mnt/cdrom # Unmount CD-ROM (drive unlocked)
[root@localhost alon]# eject /mnt/cdrom # Open CD-ROM tray
In UNIX, every file must be owned by some user and by some group. This is usually the user id and group id of the user who created the file. The user who owns the file can change the file's permissions, specifying what other users can do with the file.
File permissions and ownership information can be viewed using ls -l(long). The output looks as follows:
-rwxr-xr-x 1 root root 579384 Feb 25 2002 /bin/bash
-r-------- 1 root root 1594 Aug 25 23:09 /etc/shadow
drwxr-xr-x 18 root root 4096 Sep 1 14:41 /usr
drwx--x--x 212 alon alon 28816 Sep 19 00:47 /home/alon/
The first column is the file permissions(details below). The thrid and fourth columns list the user and group the file belongs to.
The first letter in the permissions specifies the type of the file: "-" is a regular file, "d" is a directory. The next three letters specify read(r) write(w) and exectute(x) permissions of the file's owner. The next three letters are for users in the file's group, and the last three of for the rest of the users on the system. Note that the exectute permission for directories actually means the permission to enter the directory and its subdirectories.
Permissions can be changed using the chmod command. Ownership can be changed by root only using the chown command. The default permissions for new files are set using the umask command. See the man pages of these commands for details.
Many distributions include graphical tools to assist in common administration tasks. Here is a list of a few:
Below is a list of useful UNIX commands and what they do, so you can read their manual pages:
| Command | Usage |
|---|---|
| cd |
Change directory |
| pwd |
Print working directory |
| ls |
Show directory contents |
| cp |
Copy file or directory |
| mv |
Move file or directory |
| rm |
Delete file or directory |
| mkdir |
Make directory |
| rmdir |
Remove directory |
| ps |
Show running processes (programs) |
| top |
Show CPU usage interactively |
| kill |
Terminate running process |
| df |
Show free/used disk space |
| du |
Show disk usage of specified directory |
| which |
Locate programs via path |
| locate |
Find stuff on harddisk |
Sometimes you want to do something and don't know how. What should you do now?
Linux pros are usally happy to help beginners. However, the pros will not be able to answer your question and might be mad at you, unless you follow the following guidelines: