Saturday, November 26, 2016

Linux for Newbie(Part 4.3)

Linux for Newbie(Part 4.3)

3 Job scheduling with "at", "batch", and cron

3.1 How do I execute a command at specified time (using "at" or "batch")?

The at command will execute the command(s) you specify at the date and time of your choice. For example, I could start playing music from my CDROM at 7 o’clock in the morning:
at 7:00
cdplay<Ctrl>d

In the example above, I entered the first line "at 7:00" on the command line and then pressed ENTER. To this, the at command displayed a prompt "at>". At this prompt, I entered my command "cdplay" and then pressed the control key and "d" simultaneously to finish the input. If instead of pressing <Ctrl>d , I pressed "ENTER", the next "at>" prompt would appear, at which I would be able to enter the next command to be executed right after "cdplay", also at 7:00. And so on, I could have had many commands scheduled for execution one by one starting at 7:00. After typing the last command, I would finish the input with <Ctrl>d. Think of the <Ctrl>d as sending "end-of-file" to the current input. Don’t press <Ctrl>d twice because this will log you out--that’s what <Ctrl>d does when entered straight on the Linux command line.
You can list the job you scheduled for execution using:
at -l
which will give you the numbered list of the jobs waiting.
If you changed your mind, you can remove a job from this list. For example:
atrm 8
will remove the job with the number eight on the list.
I could also schedule a job for execution much later, for example:
at 23:55 12/31/00
startx

would start my X-windowing system right on time for the new millennium (5 minutes before midnight on 31 of December 2000).

If you cannot execute the at command, check if the at daemon ("atd") is loaded (as root, use setup-"system services"). If you cannot execute the at command as a regular user although it works for root, check if the empty file /etc/at.deny exists and there is no file /etc/at.allow. This should be the default setup and it permits all the users to execute at. If you want only certain users to use at, create a file /etc/at.allow and list these users there.
For other options, check:
man at
If you wish to perform a processor-intensive job in a background when the system load is low, you may choose to use the batch command. For example, I could run setiathome (a program cranching data to help in search of extraterrestial intelligence, SETI) using:
batch
at>setiathome<Ctrl>d

In this example, I entered the command batch and then, at the "at>" prompt, I entered the command which I wanted to be executed in the background. The job tries to start immediately, but goes ahead only when the system load is under 0.8 You can check the system load by inspecting the contents of the (virtual) file /proc/loadavg . For example:
cat /proc/loadavg When a batch job finishes, the output is sent to me via e-mail.

3.2 How do I set up cron?

Cron (a Linux process that performs background work, often at night) is set up by default on your RedHat system. So you don’t have to do anything about it unless you would like to add some tasks to be performed on your system on a regular basis or change the time at which cron performs its duties.
Please note that some of the cron work might be essential for your system functioning properly over a long period of time. Among other things cron may:
- rebuild the database of files which is used when you search for files with the locate command,
- clean the /tmp directory,
- rebuilding the manual pages,
- "rotate" the log files, i.e. discard the oldest log files, rename the intermediate logs, and create new logs,
- perform some other checkups, e.g. adding fonts that you recently copied to your system.
Therefore, it may not be the best idea to always switch your Linux machine off for the night--in such a case cron will never have a chance to do its job. If you do like switching off your computer for nights, you may want to adjust cron so it performs its duties at some other time.
To find out when cron wakes up to perform its duties, have a look at the file /etc/crontab, for example:
cat /etc/crontab
It may contain something like this:

# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly

You can see that there are four categories of cron jobs: performed hourly, daily, weekly and monthly. You can modify those or add your own category. Here is how it works.
The columns in the entries show: minute (0-59), hour (0-23), day of month (1-31), month of year (1-12), day of week (0-6--Sunday to Saturday). The "*" means "any valid value".

Thus, in the example quoted, the hourly jobs are performed every time the computer clock shows "and one minute", which happens every hour, at one minute past the hour. The daily jobs are performed every time the clock shows 2 minutes past 4 o’clock, which happens once a day. The weekly jobs are performed at 22 minutes past four o’clock in the morning on Sundays. The monthly jobs are performed 42 minutes past four o’clock on the first day of every month. The directory with the script file that contain the command(s) to be executed is shown as the last entry on each line.
If you wanted your jobs to be performed at noon instead of 4 in the morning, just change the 4s to 12s. Cron wakes up every minute and examines if the /etc/crontab has changed so there is no need to re-start anything after you make your changes.
If you wanted to add a job to your cron, place a script which runs your job (or a link to your script) in the directory /etc/cron.hourly or cron.daily or /etc/cron.weekly, or/etc/cron.monthly.

3.3 Swap space

Swap is an extension of the physical memory of the computer. Most likely, you created a swap partition during the initial RedHat setup. You can verify the amount of swap space available on your system using:
cat /proc/meminfo
The general recommmendation is that one should have: at least 4 MB swap space, at least 32 MB total (physical+swap) memory for a system running command-line-only, at least 64 MB of total (physical+swap) memory for a system running X-windows, and swap space at least 1.5 times the amount of the physical memory on the system.
If this is too complicated, you might want to have a swap twice as large as your physical (silicon) memory, but not less than 64 MB.
If you ever need to change your swap, here are some basics.

3.4a Swap partitions

You can have several swap partitions, each up to approximately 124 MB. Here are the steps to create and enable a swap partition:
- Create the partition of the proper size using fdisk (partition type 82, "Linux swap").
- Format the partition checking for bad blocks, for example:
mkswap -c /dev/hda4
You have to substitute /dev/hda4 with your partition name. Since I did not specify the partition size, it will be automatically detected.
- Enable the swap, for example:
swapon /dev/hda4
To have the swap enabled automatically at bootup, you have to include the appropriate entry into your /etc/fstab file, for example:
/dev/hda4 swap swap defaults 0 0
If you ever need to disable the swap, you can do it with:
swapoff /dev/hda4

3.4b Swap files

Swapping to files is usually slower than swapping to a raw partition, so this is not the recommended permanent swapping technique. Creating a swap file, however, can be a quick fix if you temporarily need more swap space. You can have up to 8 swap files, each with size of up to 16 MB. Here are the steps for making a swap file:
- Create a file with the size of your swap file:
dd if=/dev/zero of=/swapfile bs=1024 count=8192

This physically creates the swap file /swapfile, the block size is 1024 B, it contains 8192 blocks, the total size is about 8 MB. (The dd command copies files. In the example above, the input file (if) was /dev/zero, the output file (of) was /swapfile. You cannot use the cp (copy) command for creating a swap file because the swap file must be physically continuous on the hard drive.)
- Set up the file with the command:
mkswap /swapfile 8192
- Force writing the buffer cache to disk by issuing the command: sync
- Enable the swap with the command:
swapon /swapfile
When you are done using the swap file, you can turn it off and remove:
swapoff /swapfile rm /swapfile
You may also want to see the nice info written by Linus Torvalds himself: man mkswap

3.5a Shell

3.5b What is a shell and do I want to use a different one?

A shell is the program that interprets what you type on the command line and decides what to do with it. A shell can also be invoked in a non-interactive way, for example to execute a pre-typed list of commands contained in a text file (a "shell script"). Think of a shell as an equivalent of the DOS "command.com" (command-line interpreter) and the shell script files as an equivalent of the DOS batch files (*.bat).
There are several shells available on the Linux system (if you installed them): bash ("Bourne Again" shell), sh (Bourne shell), csh (C shell, with a syntax akin to the "c" programming language), pdksh (public domain Korn shell), tcsh (enhanced C shell), ashzsh, and perhaps a couple more.
The default shell on my system (and most probably on yours too) is bash , which is an excellent and standard shell, and I really cannot see a reason why a newbie like myself would want to change it. bash is fully backwards-compatibile with the Bourne shell (the most popular shell on UNIX) and incorporates many enhancements and best features from other shells. From a newbie prospective, the different shells are included with Linux for historical reasons and backwards-compatibility of shell scripts that may require a particular shell to run.
If you wanted to try another shell, type, for example
tcsh
which will start the enhanced c shell. When done, type
exit
which will return you to the previous shell.

The shell for each user is specified as the last field in the in the password file /etc/passwd . If you really wanted to change it, edit (as root) this file and replace the "/bin/bash" with the shell of your choice.

3.5c How do I write a simple shell script?

Create a text (ASCII) file that is to contain the shell script. For example, I would use the pico editor to write a script that runs the program tar with all the parameters usually necessary to uncompress a tarball downloaded from the Internet (I never seem to remember the tar options). I decided to call my script "untar":
pico untar
Since the file "untar" did not exist in my current directory, it was created by the pico text editor. Now, I type in the content of my script:

#!/bin/bash
echo this is the script file $0
echo untarring the file $1
# this calls tar with options -xvzf (extract, verbose, filter through gzip, input filename)
tar -xvzf $1

I save the file with <Ctrl>o and exit with <Ctrl>x
The first line of the script, starting with "#!" (called pound-bang), is special--it tells the shell what program should be used to interpret the script. In this example, the script is to be interpreted by the bash shell /bin/bash . The first line must start with #! or the script will never run (the file will be interpreted as just a text file). Other lines starting with # are comments for the author (readers, users) of the shell and are totally ignored by the computer.
The $0, $1, $2 ... in my script are the parameters passed to my script. For example, if I ran a script called "myscript" with seven parameters like this:
myscript a b c d e f g
then $0 would be seen inside "myscript" as having the value "myscript", $1 would have the value "a", $2 would be "b", $3 would be "c", etc.

On the second and third line of my example script, the command echo prints on the screen everything that follows on the same line, expanding $0 and $1 to the values of the parameters passed to the script. The fourth line is a comment written to myself to remaind me what I was trying to achieve, just in case I ever had to modify my script. The fifth line performs the actual work. Once the script is written, I make the text file executable to the file owner:
chmod u+x untar
and my script is ready to use:
./untar my_tar.tar.gz

Linux scripting is definitely rich, flexible, powerful and can be complex. However, it does not require special knowledge to write simple scripts for automation of common tasks. You just put togheter a group of often used commands, one by one, into a file. I use scripting because I am too lazy to type the same groups of commands over and over again.

3.6a Simple programming

3.6b How do I write a simple Python program?

Quite like writing a shell script. Create/edit a text file that will contain your Python program:
pico try_python
Type in some simple python code to see if it works:
#!/usr/bin/env python
print 2+2

The first line tells the shell how to execute this text file. The second is a simple python expression.
After saving the file, I make it executable:
chmod a+x try_python
after which I can run it by typing:
./try_python

Python is an excellent, and very modern programming language, so give it a try. Very good (and large) free handbooks by G. van Rossum (the Python creator) are available on the net (try:http://www.python.org/doc/ for browsing or ftp://ftp.python.org for downloading).

3.6c How do I write a simple GUI program (using Tk)?

Tk is a GUI extension of the easy yet powerful tcl programming language. For example, I may use pico to create a text file that will contain a simple tk program:
pico try_tk
and type in a simple example of tk code to see if it works:

#!/usr/bin/wish
button .my_button -text "Hello World" -command exit pack .my_button

The first line (starting with the "#!" pound-bang) tells the shell what utility to use to execute my text file. The next two lines are an example of a simple tk program. First, I created a button called "my_button" and placed it at the root of my class hierarchy (the dot in front of "my_button"). To the button, I tied the text "Hello World" and a command that exists the program (when the button is pressed). Last line makes my program’s window adjust its size to just big enough to contain my button.
After saving the file, I make it executable: chmod a+x try_tk
after which I can run it by typing (in the X-terminal, because it requires X-windows to run):
./try_tk Tk is a very popular for building GUI front ends.

3.6d How do I write a simple perl script?

Perl is a scripting language famous for its power, flexibility and perhaps cryptic syntax. It is also very popular amoung linux and unix (and not only) gurus. I may use pico (or any other text editor of my choice) to create a simple perl script. The script below does nothing useful, yet illustrates some features of perl:
#!/usr/bin/perl -w
#sample perl program
# name of scalar variables start with $
$a=2;
$b=3;
print $a**$b,"\n";
$hello_world=’Hello World’;
print $hello_world,"\n";
system "ls";

The first line tells the shell how to execute my text file. The option "-w" causes perl to print some additional warnings, etc. that may be useful for debugging. The next two lines (starting with #) are comments. The following lines are almost self explanatory: I assign some values to two variables ($a and $b), put $a to power $b and print the result. The "\n" prints a new line, just like in the "c" programming language. Then I define another variable to contain the string "Hello World" and, in the next line, I print it to the screen. Finally, I execute the local operating system command "ls", which on Linux prints the listing of the current directory content. Really stupid script. Surely, I must remember to save the file, then make it executable (see the previous answers) and then I am ready to run it.

3.6 How do I compile a simple C program?

Start your favourite text editor and type in your source code. For example, I may use pico:
pico hello.c
and type in the Kerningham and Richie (the creators of "c") intro example of a C program:

#include <stdio.h>
void main(void) {
printf("hello world\n");
}

I save the file and then envoke the GNU C complier to compile the file "hello.c":
gcc hello.c
The gcc complier produces an executable binary file "a.out", which I can run:
./a.out

3.7 How do I install a program I downloaded from the Internet?

o If the program is a RedHat binary package (*.rpm), I use the RedHat package manager rpm . First I read the info on the package content:
rpm -qpi my_new_file.rpm

This queries (mode "q", must be the first letter after the dash) the yet uninstalled package (option "p") so that it displays the info (option "i") which the package contains. If I want to install the program, I run (as root):
rpm -ihv my_new_file.rpm
This runs rpm telling it to install the package (mode "i", must be the first letter after the dash) while printing to the screen more information than usual (option "h"=display "hashes" to show the unpacking progress, option "v" = be verbose). The contents of the package is distributed to the directories where it belongs. After this installation, the program is ready to run, I just have to find where the executable is. If I have trouble finding the executable, this lists all the files that the package contains together with their destination directories:
rpm -qpl my_new_file.rpm
This queries (option "q") the yet uninstalled package (option"p) so that it displays the listing (option "l") of all the files the package contains.

There are also GUI front-ends to rpm: glint (very slow, comes with RH5.2), gnopro (confusing, comes with RH6.0), and kpackage (by far the best of the three but it has to be installed separately--check your favorite Linux software site to download it).
o If what you downloaded from the net is a Linux source code in a form of a compressed tarball, the procedure is longer than with the binary-only rpm. I typically install the program as root.
First, I change my current working directory to /usr/local :
cd /usr/local
Second, I decompress the tarball that I downloaded from the net:
tar -xvzf
/home/the_directory_where_the_tarball_is/my_tarball.tar.gz

This extracts (option "x") the contents of the *.tar.gz (or *.tgz) tarball , unzips it (option "z") while talking to me more than usual (option "v" = verbose). Please note that the option "f" means "file", so the filename must immediately follow the letter "f". The contents of the tarball is extracted into a subdirectory which tar creates under my current working directory, which in this case is /usr/local/ . The tarball knows what the new subdirectory should be called.
If the tarball is not compressed, I may use:
tar -xvf /home/the_directory_where_the_tarball_is/my_tarball.tar
Third, I have a look if the new subdirectory was created and how it is called, then I cd into it:
cd the_new_program_subdir
Since some of the directories have long names, I use the great autocompletion option to save on typing--I just type the first few letters and then press <TAB> .
Fourth, most programs are compiled by executing these three commands:

./configure make
make install

The above commands can take some time to complete (0.5 h?). If any of them fail, it might be an idea to read the README or INSTALL or whatever info is provided with the new program. Some programs may require customization of the environment (e.g. addition of their directory to the PATH) or installation of an additional library, or yet something else. It can sometimes be a pain. Very simple programs might not need the "./configure" or/and "make install" step, in which case "make" alone will do.
Fifth, if everything goes well, I find the executable in the new program. The names of executables display in green when running this command:
ls --color
Now, I can run the executable:
./the_executable
Sixth, if I plan to run the program more often, I create a symbolic link to the executable from the directory /usr/local/bin :
cd /usr/local/bin
ln -s /usr/local/the_new_program_subdir/the_executable .

This way, the executable (actually, a symbolic link to it) is on my PATH and it can be run by simply typing its name (no need to type the full path to the executable any more). Some programs will put the executable (or a link to it) in a bin directory so you can skip the last step.

o There are also programs distributed as "source code rpm" packages. They require installation of the *.rpm package with the "rpm" utility and then compliation of the source code by executing the same: "./configure - make - make install" sequence as for the sourcecode distributed as tarballs.

Linux for Newbie(Part 4.2)

Linux for Newbie(Part 4.2)

Users, passwords, file permissions, and security

2.1 Home directories, root, adding users

The (almost) only place on the harddrive that normal users (non-root) can write to is their home directory, which is /home/user_login_name .
This "home" directory is for all user files: settings, program configuration files, documents, data, netscape cache, mail, etc. As a user, you can create subdirectories under your home directory to keep yourself organized. Other users cannot read your files or write to your home directory unless you give them permission to do so.
Normal users can also see, read and execute many other files on the system (besides their home directory), but they normally cannot modify or remove them.
The "root" (also called "super user") is a special administrative account that has the power to modify any file on the system. It is not a good idea to habitually work on your system as root--your mistakes can cost you dearly. Set up and use a normal user account for everyday work for yourself, another user account for your son, and yet another for your wife. The root account is the only account that exists on Linux after the initial installation.
A user account can be created by root using, for example:
adduser joe
passwd joe
[type the password for the user joe]

Root can change any user’s password, although s/he cannot read it. [Passwords are encrypted using a one-way encryption algorithm and only this encrypted version is stored on the system, in the file /etc/passwd, the "open" version is never stored. When you login, the password you type is encrypted again using the same one-way algorithm and compared with the already encrypted version stored in the file /etc/passwd (older systems) or /etc/shadow (newer systems) .]
The separation of the administrator and user makes Linux systems secure and robust--it even makes viruses under Linux difficult (the programs that a user runs can write only to his/her own directories, and therfore cannot affect the vital parts of the operating system).
It is customary that the user changes his/her password immediately after the first login, for example:
passwd
(current) UNIX password: pass_OLD New UNIX password: pass_NEW Retype New UNIX password: pass_NEW
In reality, the password will not appear on the screen as you type it (for security reasons).

2.2 About password security

Weak passwords are probably the most common source of security problems. Even at home, you may expose yourself to trouble if somebody is able to hack your computer when you browse the Internet and read your files. Here are some examples of hazardous passwords:
- no password (possible!);
- the word "password" (wow, this one is really weak!);
- your first or last name or your user login name;
- name of your wife (husband), daughter, girlfriend, dog, etc.;
- name of your company, department, workgroup, etc.;
- date of your birth;
- password written in the calendar on your desk or on the side of your computer;
- any word which is in the dictionary (the dictionary does not contain so many words as it might seem, a skillful hacker can set up a program to try them all);
- a password which you also use in an insecure public place, for example an Internet store or a mailing list.
A good password is relatively long (minimum 6 letter), contains a mixture of letters (upper and lower case, if possible) and numbers, and is changed quite regularly (8 weeks?).
The system administrator can set the password policy through the utility included in this configuration program (run as root):
linuxconf
under the menu "user account"-"policies"-"password & account policies".

Also make sure that any file that contains a password (e.g.,
/root/.kde/share/config/kppprc) has proper secure permissions so that it cannot be read by anybody. Most likely you want:
chmod 600 kppprc

2.3a I forgot the root password

Even if I never forget any passwords, I would still study this issue in detail because it can give me a hint on how my mother might be reading my ICQ chats history :-)
First method. The easiest way to solve your "forgoten root password" problem is to boot your Linux in the single-user mode, namely at the "lilo"prompt (during bootup) type:
linux single
This will make you "root" without asking for password. Now, being root, you may change the root password using this command (no knowledge of the old password required):
passwd

If it strikes you as insecure, that’s because no computer system is secure if other people have physical access to your hardware. Nevertheless, I did not like the "linux single" hole on my home computer and plugged it by adding the following lines to my /etc/lilo.conf file (at the end of the "image=" section):
password="my_password" restricted
[This "lilo" password is required when, at the LILO prompt during bootup, somebody enters the word "linux" with any parameter (normal bootup without any parameters will still be possible without a password).] For the changes to /etc/lilo.conf to take effect, I must re-run the command lilo . Since my lilo password is not encrypted, I must make /etc/lilo.confreadable only for root:
chmod 600 /etc/lilo.conf
Second Method. Another way to solve the "lost-root-password" problem is to boot your computer from the Linux boot diskette, find your Linux root partition on the hard drive, mount it, and edit the file /etc/passwd. (I can do it because after booting from the floppy, I become root without being asked for a password.) In the password file, I erase the encrypted password for root, so it is empty. For example, the /etc/passwd entry for root may look like this:
root:abcdefghijklm:0:0:root:/root:/bin/bash
The "abcdefghijklm" is a 13 character encrypted password (actually, it is a 2 character "salt" used for encryption and a 11-character encrypted password). I would change this line to:
root::0:0:root:/root:/bin/bash

Now, the root account has no password, so I can reboot the computer and, at the login prompt, type "root" and for password just press ENTER (empty, no password). After a successful login, I immediately set the password for root using the command:
passwd
The above applies to traditonal UNIX and RH5.2 password files. In newer systems (e.g., RH6.0 and RH6.1), a more secure setup is used which utilizes a shadow password file. In this case, the file /etc/passwd contains just an "x" in the field where encrypted password used to be traditionally stored. The encrypted password is stored in the file /etc/shadow . [This increases the security because of the different permissions on the files: the file /etc/passwd can be read by anybody but /etc/shadow cannot. Additionally, the shadow password system allows passwords longer than 8 characters, and adds extra goodies like password expiry policy, etc.] As root, you can manipulate the file /etc/shadow as you would /etc/passwd .
To make the "floppy access" to my system a little bit more difficult, I considered running a computer without a floppy drive :-) Unfortunately, Linux CDs are bootable these days. I set up my boot sequence (in the BIOS setup) so that the system boot from the hard drive before floppy and CDROM are tried, and added an "administrative" password on changes to the BIOS settings. Still, I worry that these BIOS passwords are so easily crackable and also one could remove my harddrive and connect it to another computer for reading :-) . I am considering an "encrypted file system" which is now available on Linux, but considering all the trouble associated with it, perhaps I will settle on locking my room :-) . If all this sound paranoid to you, it probably is--it just illustrates the point there is little computer security, even under Linux, if the potential cracker has physcial access to your hardware.

2.3b I forgot my user password.

If a regular (non-root) user forgets his/her password, this is not a problem since root can change any password. For example (as root):
passwd barbara

will prompt for a new password for the user "barbara" (no knowledge of old password required). If a user (non-root) wants to change his/her password, s/he will be asked for the old password first. (This is a security feature so nobody changes your password if you left your terminal unattended. )
If you need to temporarily disable any user account, there is no need to change his/her password. Just put an asterisk "*" at the begining of the password field (before the encryped password) in the file /etc/passwd or /etc/shadow . The "*" means that no login is permitted for this account. When you want to restore the account, you just erase the star and the user account is back in operation, with its old password.

2.4 I have file permission problems. How do file ownership and permissions work?

Linux (the same as UNIX) is a secure, multiuser operating system, and this creates a level a complexity with "files permissions". Trouble with file permissions can lead to unexpected and nasty problems. Understanding file permissions is of uttermost importance to be able to administer any multiuser operating system (be it UNIX, WinNT, or Linux). My advice would be: learn the system of Linux (or any UNIX) file permission conventions, you will not regret it.
The permission conventions are the same for normal files and directories, so whatever is said about files below, applies also to directories. It is also important to remember that lower level directories (and the files the directories contain) inherit the permissions of their parents. Therefore don’t expect to have any permissions to the subdirectory (or a file residing in it) if you don’t have any to the parent.
File owners. Each file belongs to an owner (typically a login name) and to a group. The owner is typically the person who created (or copied) the file. The group often consists of one person--the owner, and has the name identical to that of the owner, but it does not need to be so. A file can be removed (erased) only the owner of the file, or a member of the group that owns the file, or the root. Yet other users may be able to modify or erase the content of the file if they are given the permission to do so--read on. The owner and group that owns the file will be shown in the output from the ls
-l
 command (="list in the long format"). For example, the command:
ls -l junk
produced this output on my screen:
-rwx------ 1 yogin inca 27 Apr 24 14:12 junk
This shows the file "junk", belonging to the owner "yogin" and to the group "inca".
The ownership of a file can be changed using the commands chown (change owner) and chgrp (change group), which are normally executed by root:

chown peter junk chgrp peter junk ls -l junk
After executing the above 3 lines, the command ls-l junk produces this output on my screen:
-rwx------ 1 peter peter 27 Apr 25 20:27 junk

Changing the file ownership comes handy if you move/copy files around as root for use by other users. At the end of your housekeeping you typically want to hand-in the file ownership to the proper user.
File permissions . Now, an owner of a file can make the file accessible in three modes: read (r), write (w) and execute (x) to three classes of users: owner (u), members of the group (g), others on the system (o). You can check the current access permissions using:
ls -l filename
If the file is accessible to all users (owner, group, others) in all three modes (read, write, execute) it will show:
-rwxrwxrwx

Skip the first "-" (it shows "d" for directories, "-" for normal files, "l" for links, "c" for character devices, "b" for block devices). After this initial character, the first triplet shows the file permission for the owner of the file, the second triplet whows the permissions for the group that owns the file, the third triplet shows the permissions for other users. A "no" permission is shown as "-". Here is an output from the ls -l command on a file that is owned by root, for which the owner (root) has all permissions, but the group and other can only read and execute:
drwxr-xr-x 2 root root 21504 Apr 24 19:27 dev
The first letter "d" shows that the file is actually a directory.

You can change the permissions on the file which you own using the command chmod (="change mode"). For example, this command will add the permission to read the file "junk" to all (=user+group+others):
chmod a+r junk
In the command above, instead of "a" (="all"), I could have used "u", "g" or "o" (="user", "group" or "others"). Instead of "+" (="add the permission"), I could have used "-" or "=" ("remove the permission" or "set the permission"). Instead of "r" (="read permission"), I could have used "w" or "x" ("write permission" or "execute permission").
For example, this command will remove the permission to execute the file "junk" from others:
chmod o-x junk

Instead of letters, one can also use numbers to specify the permissions. To understand how it works look at this:
read=4
write=2
exectute=1
The total permission for a class of users is the sum of the three. Thus:
1 = execute only (seems unusual)
2 = write only (seems unusual)
3 = write and execute (seems unusual)
4 = read only (common)
5 = read and execute (common)
6 = read and write (common)
7 = read, write and execute (common).
The permission for all the three classes of users (owner, group, others) is obtained by gluing the three digits together one by one. For example, the command
chmod 770 junk
will give the owner and his/her group the completto of permissions, but no permissions to others. The command:
chmod 666 junk

gives all three classes of users (owner, group, others) the permissions to read and write (but not execute) the example file named "junk". Please note the "666". It is quite often used and, at least for one person I know, it is a proof that Linux (any UNIX for that matter) is a work of the devil >:-0. This command:
chmod 411 junk
would give the owner the permission to read only, and the group and others to execute only. This one does not seem useful, but might be funny, at least for those North American Linux users who dial 411 (telephone number) for directory assistance. Mail me if you can think of any other funny permissions (maybe 007?).
The numerical way of representing file permissions is called "octal" because the numbers have base 8 (the decimal system’s base is 10). The highest digit in the octal system is 7 (octal system has eight digits: 0 to 7, analogous to decimal system having ten digits: 0 to 9). The octal representation is really a convenient notation for the binary represention of file permissions, where each permission is flagged as "set" or "denied" with a one or zero and the total is represented as a string of zeroes and ones, as in this diagram:
user class: owner group others example permissions: rwx rw- r-absent permissions: --- --x -wx binary representation of the permissions: 111 110 100 octal representation of the binary: 7 6 4
Default file permissions with umask. When a new file is created, it is given default permissions. On my system, these are:
-rw-r--r-

This means that files created by a user can be read and written to be the user, but only read by his/her group and others. Still, on my default RH5.2 system, users cannot read the files in the other users’ home directories because the permissions on the home directories is:
drwx-----
I can check the default file permissions given to my newly created files using: umask -S
(The option "-S" stands for "symbolic" and tells umask to display the permissions in a easy-to-read form.)
I can change the default file permissions for newly created files using a command like:
umask u=rwx,g=,o=

which will give the owner all the permissions on newly created files, and no permission to the group and others.
Using numbers to set default permissions with umask is more tricky. The number shows the permissions that you take away for users (opposite to chmod). Thus:
umask 000
will give full permissions to everybody on newly created files. The next example gives full permissions to the owner, none for everybody else (perhaps that’s what one may want): umask 077

2.5 My mp3 player chokes. The sound is kind of interrupted (how to set suid).

The MP3 player might not be given enough processor power (it requires a lot of it). It could be that your system is lousy. Or you might be running too many cpu-intensive programs at the same time. Or, most likely, you may need to run the player with a higher priority. (The priority of a program can be set with the command nice -- see man niceorinfo nice). Try to run the player as root--programs run by root are given higher priority than those run by normal users. If this solves the problem, set the "suid" on the executable so all users are given the "effective user id" of root when running it, for example:
chmod a+s x11amp
will do the trick for the xamplifier program. The output from
ls -l x11amp
on my computer is now:
-rwsr-sr-x 1 root root 319172 Mar 13 1998 x11amp

The first "s" indicates that the substitute-user-id (suid) bit is set. The second "s" indicates that the substitute-group-id (sgid) is also set. Thus anybody who executes x11amp is given the effective user id of the program owner and effective group id of the owner group, which in the example above is the user "root" and the group "root".
Setting the suid for a program could possibly become a security hole in your system. This is unlikely the case on a closed home network and when setting suid for a program origin of which is well traceable. However, even at home, I wouldn’t suid a piece of code origin of which is uncertain, even if the setup instructions urged me to do so.
Some programs do however require suid for proper functioning, for example kppp (the popular modem "ppp" conection utility under the KDE graphical-user-interface desktop).

Linux for Newbie(Part 4.1)

Linux for Newbie(Part 4.1)

Basic Operations FAQ 

1 Basics

1.1 Filenames

Linux is case-sensitive. For example: my_filE, my_file, and my_FILE are three different files. Your password and login name are also case-sensitive. (This follows the tradition since both UNIX and the "c" programming language are case-sensitive.) Naming conventions for files and directories are identical.
Filenames under Linux can be up to 256 characters long and they normally contain letters, numbers, "." (dots), "_" (underscores) and "-" (dashes). Other characters are possible but not recommended. In particular, it is not recommended to use special metacharacters: "*" (asterisk), "?" (question mark), " " (space), "$" (dollar sign), "&" (ampersand), any brackets, etc. This is because matacharacters have special meaning to the Linux shell. It is possible to have space inside the filename, but we don’t recommend it either--we use underscore instead.
It is not possible at all to have ’/’ (slash) as a part of the filename because ’/’ is used to represent the top of the directory tree, and as a separator in the pathnames (the same as ’\’ is in DOS). To manipulate files with names that do contain matacharacters, I use a pair of ’ (apostrophes), so that the metacharacters are quoted and therefore the shell does not interpret their meaning. For example, to remove a file my file* (contains space and asterisk), I would issue:
rm ’my file*’
Please note that I use a pair of ’ (apostophes) for quoting. Quoting with a pair of " (quotation marks) is generally weaker than quoting with ’ . When you use " some metacharacters may get interpreted.

Here is the meaning of some metacharacters:
* = Matches any sequence of zero or more characters (except for "." dot at the beginning of a filename).
? = Matches any single character.
[abC1] = Matches a single character in the enumerated set. In this example the set is: ’a’, ’b’, ’C’, or ’1’.
[a-z] = Matches any lower-case letter.
[A-F] = Matches any upper-case letter from A to F in the Latin alphabet.
[0-9] = Matches any single digit.
[a-zA-Z0-9] = Matches any letter (lower or upper case) or any digit.
Examples. This command will show any filename in the current directory, with the exception of filenames starting with "." (dot):
ls *

An equivalent to this command is to type just "ls" or "dir". Files with names starting with "." are not shown
because "." as the first character of a fileneme is not matched by "*". Think of files with names starting with "." as an equivalent of DOS hidden files. Use ls -a (list with the option "all") orls .* to see these "dot" files. The dot-files are common in the user home directories and are typically used to hold user-level configurations.
This command will show any filename that contains a dot: ls *.*
This command will show any filename that contains two dots:
ls *.*.*
Please note that Linux does not have "filename extensions" and some other DOS-like file-naming features ("Micros~1.doc" comes to mind).
This command will show all filenames in the current directory that start with "a" or "b", or any capital letter:
ls [abA-Z]*

As an example of problems that you might face when using non-recommended characters in a filename, try creating a file with a name starting with a dash and then remove it--there seems to be no way to do it (a dash normally introduces command options). E.g., the command
dir > -junk
will create such a funny file (the symbol ">" redirects the output from the dir command to a file named -junk). Since the regular way of removing the file -junk does not work, I use: rm ./-junk
The dot slash at the beginning means "the current directory" and here just serves the purpose of hiding the leading dash so it is not interpreted as introducing an option to the rm command. The point here is that I rather stick to traditional naming conventions than face the occasional complications.

1.2 What are the different directories for?

This is explained very nicely in the Linux System Administrator Guide (SAG), which should be available on your system. Try:
cd /usr/doc/LDP/sag
lynx sag.html

This will start a text-mode browser "lynx" to view this html book. You can also use any other browser, e.g. Netscape for Windows, to view this book. This book and other LDP books are actually quite easy to read.
Briefly, Linux contains five filesystems. These filesystems can reside on a single or different physical hard drives and/or hard drive partitions, depending on the size and need of your system. (A single filesystem can also be distributed between different physical devices, if needed.)
The root " /" filesystem--contains basic operating system and maintenance tools. The content of this filesystem should be sufficient to start up the system and perform emergency maintenance and repairs if they were necessary.
/usr filesystem--contains all commands, libraries, documentation, and other files that do not change during normal operation. This will also contain major applications, perhaps the ones that come with your distribution, for example Netscape.
/var filesystem--contains files that change: spool directories, log files, lock files, temporary files, and formatted manual pages.
/home filesystem--contains user files (users’ own settings, customization files, documents, data, mail, caches, etc).
/proc filesystem--contains entirely illusionary files. They don’t really exist on the disk and don’t take any space there (although ls -l will show their size). When viewing them, you really access information stored in memory. It is used to access information about the system. The parts of the root filesystem are:
/bin--commands needed during bootup that might be used by normal users.
/sbin--commands not intended for use by general users (users may still use them). /etc--system-wide configuration files for your operating system.
/root--the home directory of the system administrator (called super-user or root). /dev--device files. Devices appear on Linux as files so it is easy to write to them. /mnt--mount points for removable media (floppy, cdrom, zipdrive), partitions of other operating systems (like dos), network shares, and anything else that is mounted on the file system temporarily. It normally contains subdirectories for the mounting shares.
/lib--shared libraries for programs that reside on the root filesystem.
/boot--files used by LILO (a bootstrap loader, the thing that loads first when the computer is booted and perhaps gives you an option which operating system to boot, if you have more than one OS on your computer). It typically also contains the Linux kernel, but this can be stored somewhere else, if only LILO is configured to know where it is.
/opt--optional large applications, for example kde under RedHat 5.2 (under RedHat 6.0, kde is distributed as any other X-windows distribution, main executables are in the /usr/bindirectory). /tmp--temporary files. This directory may clean automatically.
/lost+found--files recovered during the filesystem repair.
The most interesting parts of the /usr filesystem are:
/usr/X11R6--X-windows system.
/usr/X11--the same as /usr/X11R6 (it is a symbolic link to /usr/X11R6).
/usr/X11R6/bin --lots of small X-windows apps, and perhaps symbolic links to the executables of some larger X-windows applications that reside in other subdirectories).
/usr/doc--Linux documentation.
/usr/bin and /usr/sbin--similar to their equivalents on the root filesystem (/bin and /sbin), but not needed for basic bootup (e.g. during emergency maintenance). /usr/local--the installed "local user" applications, for example Netscape (each application in a separate subdirectory).
/usr/local/bin--perhaps smaller "user" apps, and symbolic links to the larger executables contained in separate subdirectories under /usr/local .
It is important to understand that all directories appear in a single directory tree, even if the directories are contained on different partitions, physical drives (including floppies, etc), or even if they distributed over the network. Therefore, there are no DOS-type "drive letters" under Linux.

1.3 How do I run a program?

Typing the name of the executable on the command line doesn’t help? There are three possibilities.
The first possibility: you don’t type the name of the executable correctly. Check the case--Linux is case sensitive! For example, typing "Pico" or "PICO" will not start thepico editor.

The second possibility: maybe the program is not on your PATH. Under Linux (or UNIX), an executable must be on your PATH to run it, and the current directory is NOT on your PATH. Type the full path to the executable with the executable name, or execute:
cd the_program_dir ./program_name
You must put the dot and slash in front of the program name or the program will NOT execute. (This is a security feature not to put one’s current directory on the path. It makes "trojan horses" more difficult. A "trojan horse" is a malicious program that pretends to be something different than it really is.) This dot means "the current directory", and the slash "/" is a separator between the directory name and the filename (exactly as "\" in DOS).
You may check your path using:
echo $PATH
To learn how to change your PATH, or add your current directory to it, see the next answer [p 33] . 
If your executable is lost somewhere in your directory tree, you may want to find it using (for example):
find -name "netscape"
to find a file called "netscape". You may be able to achieve the same result faster using:
locate netscape
(Locate runs faster because it relies on a pre-built database of files on your system. This database if updated by a background cron process that normally runs at night, so don’t count on locateto find a file if you regularily switch off your computer for the night, or you search for a file that you just installed.)
Please note that the PATH is normally different for root than regular users (root’s PATH includes /sbin and /usr/sbin whereas users’ don’t). Therefore users cannot execute command located in the "sbin" directories unless they specify the full path to the command. Also, if you become a superuser by executing the su command, you inherit the user’s PATH, and to execute the command located in sbin, you need to specify the full path.
Conversly, if you need to learn where an executable which is on your PATH is located on your system (i.e., the executable runs by typing its name anywhere in the system, but you would like to know where it is), you may use something like this:
which netscape
which will show a full PATH to the executable program called "netscape".
The third possibility: maybe the file is not executable. If it should be, change the permissions to make it executable. E.g. (as root or the user who owns the file):
chmod a+x my_file
will make the file "my_file" executable for all users. Check if it worked using: ls -l my_file Read here [p 41] if you don’t understand the output of this command or the whole "third possiblity".

1.4 How can I change the PATH?

The PATH is the list of directories which are searched for the program the execution of which you request. You can check your PATH using this command:
echo $PATH
which, on my system , shows the PATH for the user "yogin" to be:
/opt/kde/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/home/yogin/bin
The ":" is a separator, therefore the above PATH represents a list of directories as follows:

/opt/kde/bin
/usr/local/bin
/bin
/usr/bin
/usr/X11R6/bin
/home/yogin/bin

Here is the output from the command "echo $PATH" run on my system on the account "root":/opt/kde/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin
You can change the PATH for all users on the system by editing the file /etc/profile and adjusting (as root) the line starting with "PATH=". I do it using the pico editor (as root):
pico -w /etc/profile
(The option -w turns off the wrap of long lines.)

Re-login for the change to take effect. To set up the PATH for an individual user only, edit the file /home/user_login_name/.bash_profile (please note the dot in front of the filename--files starting with a dot are normally invisible, you have to use ls -a to see them).
If you really want to have the current directory on your PATH, add "." (dot) to your PATH. When used in the place when directory name is expected, a dot means "the current directory". The specification for the path in /etc/.bash_profile may then look like this:
PATH="$PATH:$HOME/bin:"."
export PATH

This command takes the contents of the environmental variable called PATH (as set for all users in /etc/profile), and appends to it the name of your home directory as set by the variable HOME with an attached "/bin" and then a dot. Finally, the command assigns the resulting string back to the variable called PATH. It is necessary to use the command "export" after modifying PATH or any other user-enviroment variable, so that the variable is visible outside of the script that sets it.

1.5 How can I shutdown my computer?

In a text terminal, press <Ctrl><Alt><Del>, wait for the shutdown process to complete, and turn off your machine only after it starts rebooting again. If you are in X-windows, first switch to a text terminal by pressing <Ctr><Alt><F1> (three keys simultanously). Do not turn off your machine without the proper shutdown or else you may have disk error messages next time you boot. (Typically, the errors resulting from improper shutdown will be repaired automatically during the next boot, but occassionally more serious problem may result, and then you may need to repair the files manually or re-install!)
If you prefer your computer to go to the halt after you press <Ctrl><Alt><Del> (instead of the default reboot), you can set this up by editing the file /etc/inittab. This file specifies something like this:
# Trap CTRL-ALT-DELETE
ca::ctrlaltdel:/sbin/shutdown -t3 -r now

Change (as root) the option "-r" to "-h" so that it reads:
# Trap CTRL-ALT-DELETE
ca::ctrlaltdel:/sbin/shutdown -t3 -h now

The line starting with "#" is just a comment (it is for the humans, it does not have any effect on the computer).

Root can also use the shutdown command. This command can be used for either a local or remote shutdown of the system. The last one is very useful if a program hangs so that the keyboard is no longer functional. For example:
telnet name_of_machine_with_no_operable_keyboard
[login as a user]
su
[give password]
Now either execute ps axu |more, find the process id of the offending command in the ps output and do
kill pid_of_offending_process, or reboot your machine with:
/sbin/shutdown -rn now
This command will shutdown really fast, bypassing standard (longer) shutdown procedure--useful when the system becomes really buggy (the option -n will make "shutdown" kill all the processes before rebooting).
Please note that for security reasons, you cannot login to a remote machine as root (e.g., over the telnet). You have to login as a user and then execute su and give a password to become a super user (root).
The shutdown command may also be used to execute a shutdown later. E.g. (as root): /sbin/shutdown -r 23:59
will reboot the system 1 minute before midnight.
If the shutdown command is too long for you, you may want to try these two commands, which do exactly what their names suggest (as root):
reboot halt
A fancy way to shut down your computer is to switch your system to the runlevel 0 (for halt) or runlevel 6 (for reboot). Try it using (as root):
init 0 The meaning of the different runlevels is explained in the file /etc/inittab
 and here.

1.6 How do I deal with a hanged program?

Buggy programs do hang under Linux. A crash of an application should not, however, affect the operating system itself so it should not be too often that you have to reboot your computer. In our experience, a misbehaving operating system may be a sign of hardware or configuration problems: we repeatedly encountered problems with the Pentium processor overheating (the fan on the Pentium did not turn as fast as it should or it stopped altogether, the heat sink on the Pentium was plugged with dirt), bad memory chips, different timing of different memory chips (you may try re-arranging the order of the chips, it might help), wrong BIOS setup (you should probably turn off all the "advanced" options, Linux takes care of things by itself). The "signal 11" error message is typically associated with hardware problems and it most likely to manifest itself when you perform computing-intensive tasks: Linux setup, kernel compilation, etc.
Not really hanged. Some programs might give the uninitiated impression of hanging, although in reality they just wait for user input. Typically, this happens if a program expects an input file name as a command line argument and no input file is given by user, so the program defaults to the standard input (which is console). For example, this command
cat
may look like it’s hanged but it waits for keyboard input. Try pressing <Ctrl>d (which means "end-of-file") to see that this will satisfy the "cat" command. Another example: I have seen many questions on the newsgroups about the "buggy" tar command that "hangs" when trying to uncompress a downloaded file, for example:
tar -zxv my_tar_file
This waits for user input too, since no option "-f filename" was specified so the second parameter "my_tar_file" was not recognized as a filename. The correct command is:
tar -zxvf my_tar_filename
Please note that the filename must follow immediately after the option "f" (which stands for "filename). This WILL NOT work (very common mistake):
tar -zxfv my_tar_file

Any program (hanged or not) can be killed. A text-mode program in the foreground can often be killed by pressing <Ctrl>C. This will not work for larger applications which block the <Ctr>C, so it is not used on them accidentally. Still you can get back in control either by sending the program to the background by pressing <Ctrl>z (no guarantee this will work) or switching to a different terminal, for example using <Ctrl><Alt><F2> and login as the same user that hanged the program (this should always work). Once you are back in control, find the program you want to terminate, for example:
ps
This command stands for "print status" and shows the list of programs that are currently being run the current user. In the ps output, I find the process id (PID) of the program that hanged, and now I can kill it. For example:
kill 123
will kill the program with the process id (PID) of "123".
As user, I can only kill the processes I own (this is, the ones which I started). The root can kill any process. To see the complete list of all processes running on the system issue:
ps axu | more

This lists all the processes currently running (option "a"), even those without the controlling terminal (option "x"), and together with the login name of the user that owns each process ("u"). Since the display is likely to be longer than one screen, I used the "more" pipe so that the display stops after each screenful.
The kill command has a shortcut killall to kill programs by name, for example:
killall netscape
will kill any program with "netscape" in its name.
X-windows-based programs have no control terminals and may be easiest to kill using this (typed in an X-terminal):
xkill

to which the cursor changes into something looking like a death sentence; you point onto the window of the program to kill and press the left mouse button; the window disappears for good, and the associated program is terminated.
If your X-windows system crashes so that it cannot recover, it may be the easiest to kill the X-server by pressing <Ctrl><Alt><BkSpace>. After that, it may be a good idea to run ps axu, find any possible X-programs that might still be running, and kill them. If you don’t do this, the misbehaving program that caused your X-windows to crash might cause trouble again.
If you have programs in the background, the operating systems will object your logging out, and issue a message like "There are stopped jobs". To override and logout anyway, just repeat the logout (or exit) command immediately --the background program(s) will be automatically terminated and you will be logged out.
Core files. When a program crashes, it often dumps a "core" into your home directory. This is accompanied by an appropriate message. A core is a memory image (plus debugging info) and is meant to be a debugging tool. If you are a user who does not intend to debug the program, you may simply delete the core:
rm core
or do nothing (the core will be overwritten if another core is ever dumped). You can also disable dumping the core using the commmand:
ulimit -c 0
Checked if it worked using:
ulimit -a

(This shows "user limits", the option "-a" stands for "all"). To make option of disabling core dumps permanent for all users, edit the file /etc/profile (as root), where ulimit is set, and adjust the setting. Re-login for the changes to /etc/profile to take effect.
If you would like to see how a core file can be used, try (in the directory where you have a core file):
gdb -c core

This launches GNU debugger (gdb) on the core file "core" and displays the name of the program that created the core, signal on which the program was terminated, etc. Type "quit" to exit the debugger. To learn the meaning of different signals, try:
cat /usr/include/bits/signum.h

Linux for Newbie(Part 2)

Linux for Newbie(Part 2)

Before Linux Installation

1 Which Linux distribution should I use?

The differences between the distributions ("distros") are minor: the installation program, choice of the bundeled tools/applications, arrangement of a few things on the hard drive (most of Linux is still at the same, standard hard drive location in all distributions). Whichever distribution you decide to install, you will end up with essentially the same Linux.
We mostly use "Red Hat Linux" (also called RedHat or RH) for these reasons:
(1) RedHat is very popular (both advantage for a newbie and a testimony to RedHat quality). (2) RedHat is a general-purpose distribution.
(3) RedHat comes with a relatively easy setup program.
(4) RedHat contributions to Linux are "open software" (this means that all the software written by RedHat and included on the RH distribution CD is lisensed under the General Public License, GPL, so that it can be legally copied, given away, reused, etc.).
(5) RedHat can be obtained very cheaply or free if you don’t care for commercial support. This is a consequence of (4).
In short, as a newbie, you can safely bet on "Red Hat" unless you like something else or have specialized needs. The most recent RedHat release (October 1999) is version 6.1 (called RH6.1) which is only a relatively minor upgrade over the previous version of RedHat 6.0 (RH6.0) which hit the street in May 1999. The yet previous version was RedHat 5.2 and it was very popular for quite a while. Be sure to specify the most recent version if ordering your software from a dealer--many dealers like to clear their inventory by sending you an old version (this applies not only to Linux). The authors have no connection to RedHat (or any other Linux distributor) whatsoever.
Our recommending RedHat for newbies does not mean that other distributions don’t offer benefits or unique features which may surpass RedHat in specific areas. We do believe that we benefited from an exposure to a different distribution because it helped us understand Linux better.
We tried Debian and we liked it very much. It was probably as easy as RedHat, but it seems less common (hence, being newbies, we picked up RedHat). The great benefit of Debian is that it is 100% non-commercial (put together by volunteer hackers, the true Linux way) and it probably most strictly adheres to Linux standards (it probably sets the standards too). Another benefit is that Debian crams on their numerous distribution CDs thousands of tools and applications--easily much more than any other distribution. All these tools/apps are nicely "packaged" (for ease of installation) and tested for compatibility. This makes Debian distro look monumental, safe, conservative, and always slightly outdated. So yes, we would not have a problem recommending Debian for as a great general-purpose Linux distribution.
Corel is currently beta-testing their own Linux distribution apparently geared towards a nice and easy platform to run the Corel suite of office applications: WordPerfect wordprocessor, QuattroPro spreadsheet, Corel Presentations, Paradox database, CorelDraw artist package.... The Corel Linux is based on Debian. So if you think about using Corel in the future, picking Debian may be your smart choice now.
Slackware seems to be favorite among "cutting-edge hackers" who like being close to the operating system and perhaps upgrade their kernel every other day--we did not use it so this is hearsay. S.u.S.E distribion is very popular in Europe. It surely looks German-solid, general-purpose distro with an easy setup and an excellent reputation. Another well-known and respected distribution is Caldera, said to be aiming at corporate users--it has the most fancy, perhaps most easy installation program. Mandrake distribution is a RedHat clone which is updated more often than the pedigree RedHat (RedHat tends to update less often so as not to proliferate too many versions). Mandrake seems to be very popular lately. There are "localized" versions of Linux for specific countries or languages (Korean, Chinese, Japanese ...)--they likely contain on default all the hacks and docs that the users in these countries probably want to see.
There are also "special purpose" distributions, e.g. the "real-time" editions of Linux (might be useful if you are in for automation, robotics, etc.), very small distros (could be good for the next-generation CD/MP3 player or if you like the idea of running Linux from a single floppy), parallel computing and clustering systems (might be great if you plan to do your own weather forcasting :-) ), etc. Here the differences will be larger, but these distributions are not meant to be "general purpose". As a newbie, you likely don’t want to start with any of these, although you might be tempted to. (They surely show Linux strength and viability--it runs on toys as well as computer clusters that make the currently fastest systems in the world.)
The distribution you need is of course specific to the hardware platform you have. This means that for your PC hardware containing a Intel 386 processor, or 486, or Pentium, or Cyrix, or K6, or similar, you need the binary distribution called "Intel" or "386". [Unless you are prepared to start with your own compilation of the Linux source code, which is not typical for a newbie :-)] This happens because there are binary distribution for other platforms too (PowerPC, Alpha, and perhaps a dozen more)--don’t get those for your PC clone, surely they will not work.
In short, although newbies get confused with the multiple Linux distributions, there are reasons to have different distros. They should be viewed as a Linux strength rather than weakness.
This guide concentrates on RedHat 5.2, 6.0 and 6.1 on the PC (Intel) platform. Many of the answers will work fine on other distributions or platforms, but we did not try them.

2 What are the Linux hardware requirements?

"Out-of-box" Linux will run on a 386SX-based PC with 8 MB of memory, but such a low-end computer is practical for text-only applications (no X-window). A 486 with 16 MB memory and 600 MB free (unpartitioned) hard drives will do for work with X-windows. My 586-90 MHz with 64 MB of memory flies under Linux. My Pentium-2 233 MHz with 64 MB of memory is a complete pleasure with an almost instantaneous response even when running many large applications concurrently. My 486-33 MHz with 8 MB memory and 1 GB hard drive has too little memory to run adequately stand-alone under GUI, but is useful in my home network environment (a 486-class machine performs just adequately also stand-alone if it has at least 16 MB of memory). My old portable 386-SX-20 MHz Toshiba with 9 MB memory and 120 MB hard drive runs "legacy applications" under MS Windows 3.11 and connects to our Linux home network and is thus still useful. We tried Debian Linux on this Toshiba too, and it runs fine in text mode. If you are willing to jump through a few extra hoops, you should be able to install and run Linux on a little as 4 MB of memory, but this is probably not worth the effort for the general purpose home Linux machine. I would say: get at least 16 MB of memory, and if possible 32 or 64 MB --more memory can make a difference in performance when running concurrently several large GUI applications. Memory is cheap these days.
Networking is where Linux really shines, so consider getting 10-base-T Ethernet cards--they are not very expensive and will be perfect to connect your two or more home computers together. Also, look around for old Ethernet cards which MS Windows deems obsolete--they can be bought for a really low price and they will work fine under Linux. To connect just two computers, a cross-over cable for direct Ethernet-card to Ethernet-card connection is sufficient. To connect more than 2 computers together, you need a hub (~US$30 to US$80) and normal (not cross-over) cables. (If you have extra Ethernet cards, you may also consider installing more than 1 Ethernet card on a computer, use direct connections using the cross-over cables, and save the expense of a hub. ) The 10-base-T system uses "giant phone" (RJ45)-type connectors and all machines are connected to one box (called the hub). The hub has an extra connection (called "uplink") which you will use if you ever have a permanent connection to the outside world.
Here is another suggestion on setting up a different kind of network, older type, which uses coaxial cables. For this, no hub is necessary. Because this networking scheme is older, it can be assembled using cards and parts that are often available almost for free:
(edited for space) From: John.Edwards@brunel.ac.uk Subject: Linux Guide-a suggestion
Hi. Many older 10Mbps network cards (and some newer ones as well) have a BNC connector and you can usually pick up old co-axial cabling when companies upgrade to UTP. Add a T piece for each machine and a 50-ohm terminator at each end (about 1 pound or $1.50 each) and you have a home network that will happily support more machines than you probabily have room for. And most importantly--no expensive hub (or cheap hub that can cause trouble). There are other advantages to co-ax as well, it’s tougher to break and more resistent to noise from other equipment.
Disadvantages: There is a limit of 185 metres per network segment of thin co-ax, 30 machines per network, and you’re stuck at 10Mbps, but I don’t see any small home network needing more than that. Also if one cable goes down then the whole network stops, this shouldn’t happen often unless someone unplugs a cable section. You can disconnect the T piece from a PC without harming the rest though.
Quick diagram, T for a T piece and Term for a terminator:
Term-T-----T-----T-----T-Term | | | | PC PC PC PC
The various parts connect together using BNC connectors similar to TV & video connector but with a bayonet that secures the two sockets together.
For more detail see page 6 of the /usr/doc/HOWTO/Ethernet-HOWTO

3 Will my hardware work under Linux?

Not every piece of PC hardware is supported under Linux, but most are, particularly the more standard, older, and popular ones. This applies to SCSI adapters, CDROMs, writable and rewritable CDs (CD-R and CD-RW), video cards, mice, printers, modems, network cards, scanners, Iomega drives, etc.
The most notable exceptions are the so-called Winmodems (=MS Windows modems). Avoid these like fire--they are maybe $5 less expensive than full modems, but they are crippled and there is little chance they will ever work under a normal operating system (they may not even work with the next version of MS Windows). External modems are never "MS Windows modems" so if in doubt, purchase an external modem (external modems are more expensive, but they don’t drain your PC power supply, are easily portable between machines, look better, and show modem activity).
Another area of potential problem is the video card. If you have a recent "cutting edge" 3D or uncommon card, you may want to check its compatibility at http://www.Xfree86.org.
So the short answer is yes, in all likelihood your standard PC will run Linux with no problems. You don’t invest much when trying Linux, so probably the easiest way to make sure is to attempt an installation on your existing hardware. There are Linux hardware compatibility lists at http://www.redhat.com/support/docs/hardware.html and 
http://metalab.unc.edu/LDP/HOWTO/Hardware-HOWTO.html if you want to check your newer or less popular hardware.
When purchasing new hardware, ask your supplier if the hardware is supported under Linux or consider a system with Linux pre-installed. Not too many major suppliers offer one yet (most plan to), but you can get one from a smaller vendor.
If a piece of hardware of yours is (apparently) not supported in your current Linux distribution, don’t give up. Chances are that: 1. It is supported, but you don’t know how to set it up. (Solution: stay around with Linux for a few days or weeks, don’t waste your time, when you get some understanding of how your system works, then you may be able to set it up.) 2. You have to go through a more complex setup to support the hardware (for example some cryptic command or a kernel re-compile, which is not as difficult as it seems). 3. An updated (different?) distribution already supports it "out-of-box" (you can usually order it for US$1.99). 4. There is already an upgrade somewhere on the Internet, you have to find it, download it, and figure out how to install it. 4. The upgrade will be available next week--Linux development goes really fast!

4 How do I download Linux?

Do yourself a favor and do not download Linux, get an installation CD instead. Linux can be downloaded completely from the Internet, but it is a large and sophisticated operating system. The download will take hours or days of download time and you will probably encounter problems when trying to stitch the downloaded pieces together.
If you do have a speedy Internet connection (definitely not a 28.8-modem) and you are not a 
complete newbie, Linux download may be an option to you after all. Try: ftp://ftp.redhat.com/pub/ if the site is not too busy today.

5 How do I get a Linux CD?

Many possible ways. (1) Buy the "RedHat" CD from linuxmall (http://www.LinuxMall.com/), or cheapbytes (http://cart.cheapbytes.com/cgi-bin/cart )--last time I checked , "the unofficial" RedHat 6.1 GPL was US$1.89 and US$1.99 respectively + shipping and handling. They will mail you a bare CD. You get no printed manual, no support, no boot diskette, but the price is right, and the manual and tools to make a boot diskette are on the CD. I purchased several packages from "cheapbytes" and they always arrived fast, were of good quality, and there were no problems with my credit card charge (the authors have no connection to "cheapbytes" whatsoever). (2) Buy the boxed "official Red Hat" from the same place on the Internet or from your favorite software supplier, prices start at around US$40--you will get the printed manual, e-mail or telephone installation support (60 days?), the boot diskette, additional CDs with "bundled" commercial applications, and perhaps other goodies (free updates?). (3) Copy the installation CD from your friend. This is perfectly legal and ok--Linux is free. If you have a Linux CD, don’t be shy to loan it to your neighbor. (4) Check your library, local bookstore, or http:/www.amazon.com. Several Linux handbooks come with an attached CD containing a full Linux distribution. This is a good way to start with Linux! It is definitely a good idea to have a nice Linux handbook. With Linux countless utilities, I need a handbook all the time. (5) Visit a Linux "installfest" when one is organized in a place near you. Local Linux "gurus" will install Linux on your computer free (bring the computer) and you will likely be able to get a Linux CD too (why don’t you bring 1 or more empty CD-R to the fest?). Check for the Linux User Group on the net to see when the nearest to you plans an installfest. Good way to meet other Linuxers too. (6) If you are really short on cash or are a Linux pioneer in one of these places in the world where US$2 goes a long way, try "linux exchange" or "giveaway"--people loan or donate Linux CDs (e.g. try: http://visar.csustan.edu/giveaway.html). If you live in a major city, you may even get lucky and somebody will help you with your first Linux installation / setup. If you can’t find anything, let me (bklimas@magma.ca) know. I’ll try to arrange sending a copy of Linux CD to you (if you are not a joker). Once again, if you have a Linux CD, don’t be shy to loan it to your neighbor.

6 I have RedHat CD but no install floppy. What do I do?

If your computer can boot from the CD drive (most computers cannot), you don’t need a boot diskette to install Linux. Have a look at your BIOS setup, the boot sequence can often be set up there. My computer has the CD drive specified as the first boot device in the BIOS yet still cannot boot from the CD drive. So the BIOS setup does not necessary reflect the capability of your machine. If you can boot from CD drive, just insert the RedHat CD into the CD drive and reboot the computer to enter the RedHat Linux installation program.
If you don’t know how to access your BIOS setup, read this paragraph. The BIOS setup can typically be entered at boottime by pressing the proper key at the right moment (often when a prompt is briefly displayed). Most often, it is the <Del> key. Here is a list of key combinations used by popular BIOSes: Acer notebooks: <F2> during Power-On Self-Test (POST). American Megatrends (AMI): <Del> during Power-On Self-Test. Award: <Del>, or <Ctrl><Alt><Esc>. Compaq: <F10> after the square appears in the top right corner of the screen during boot-up. Dell: <Ctrl><Alt><Enter>. DTK: <Esc> during Power-On Self-Test. IBM Aptiva 535: <F1> while the square with the wavy lines is displayed in the upper right corner during power-on. IBM PS/2: <Ctrl><Alt><Del>, then <Ctrl><Alt><Ins> when the cursor is in the top right corner Mr. BIOS: <Ctrl><Alt><S> during Power-On Self-Test. Packard Bell: For some models, <F1> or <F2 > during Power-On Self-Test. Phoenix: <Ctrl><Alt><Esc> or <Ctrl><Alt><S>, or <Ctrl><Alt><Enter>.
If your computer cannot boot from the CD drive, make an install boot diskette from under DOS or the MS Windows DOS mode. (You have go to to "Shutdown" and "Restart in MS-DOS mode", not just run a DOS window). From DOS, you may try the program:
EZSTART.BAT
which is on my RedHat CD from "cheapbytes".

It is important that you have a perfectly good floppy (without even one bad cluster). The program that makes the diskette does not check if the floppy was written properly. Also don’t count that the DOS FORMAT utility will find a faulty floppy--it probably won’t. If I were you, I would make two or three boot floppies at once--you may be surprised how many diskettes have problems. For me, the third floppy worked! If your install diskette does not boot, make another one--it definitely should boot.
If you don’t have the EZSTART.BAT, here are the essential commands. To make the boot floppy run:
F:\dosutils\rawrite.exe -f F:\images\boot.img -d a: -n
To make the supplemental (optional) diskette run: F:\dosutils\rawrite.exe -f F:\images\supp.img -d a: -n
This assumes your CDROM is the DOS "F:" drive, and your floppy is "A:", adjust the commands if the drive letters are different on your system.
You may find it easier to run rawrite without any argument--it will interactively prompt you for the input image and output file.
From under Linux, you can make a boot disk by mounting the RedHat CDROM and typing the commands (as root user):
cd /mnt/cdrom/images/ dd if=boot.img of=/dev/fd0

[The ‘‘dd’’ command copies files. The above command specifies that the input file ("if") is ‘‘boot.img’’ and the output file ("of") is /dev/fd0, which is the first floppy drive, i.e. the floppy drive number zero (if you want to write to your second floppy drive, use /dev/fd1). ]

7 What do I need to read before installation?

You may want to read the RedHat manual. If you don’t have the printed copy, an html version is on your CD so you can read it using any web browser, e.g. Netscape for Windows. Look here to see how to access this manual and some additional reading material.
It is also helpful to get some UNIX orientation if you don’t have any. Buy a good Linux manual or dust your old Unix handbook. Almost all basic Unix commands will run fine under Linux. Manuals for MS Windows are useless (click this, click that), but manuals for Linux/UNIX are typically great (give you an understanding of the system, a lasting benefit).
You may want to learn about your hardware: how many and what size hard drives you have, the type, number, order and size of all partitions on each drive, where are your DOS/Windows partitions, which one is the DOS/Windows boot partition (if you plan to have dual boot), what type of mouse you have, what video card and with how much memory, what monitor (max synchronization frequencies), etc.
Go to BIOS setup to see the number and geometry of your hard drives. Run DOS "fdisk" to display your hard drive(s) partition table(s). Watch your system boot to learn about the type of your video card and the amount of video memory. Boot MS Windows, go to the control panel-devices and write down the sound card, modem, network card types and settings (name, type, IRQ, i/o address, DMA channel). Read the label underneath your mouse to see the type of mouse you have. (Next time you buy a mouse, get a Linux-ready 3-button Logitech or similar--Linux makes good use of all three buttons.) Dust off your monitor manual to find out the maximum synchronization frequencies (vertical and horizontal) that your monitor supports. Never use freqencies out the the monitor specification--this may damage your monitor.

8 Can I have MS Windows and Linux installed on the same computer?

Yes, you can. Many Linuxers use dual boots. This is typically achieved by installing MS Windows on one hard drive partition and Linux on another partition. Linux comes with a simple boot manager called LILO, which will let you choose at the boot time the operating system you boot. Install MS Windows first and Linux only afterwards or else MS Windows installation program will disable your access to Linux. Have a Linux boot floppy ready if you need to re-install MS Windows--MS Windows will surely disable your access to Linux and you will have to boot Linux from the floppy and then re-run the command lilo to get back to business.
From under Linux, you will be able to read from and write to your MS Windows drive partitions so that data exchange between MS Windows- and Linux-based program is seamless. You will also be able to use your existing MS Windows-based resources: sound files, backgrounds, pictures, fonts, etc. (First check if it does not violate your license agreement :-) though. For products that are on rent to you from Microsoft, it probably would. With my Linux computers, I am proud to have no pirated software on my system whatsoever.)

9 How do I partition my hard drive?

If you plan a dual boot (Linux and MS Windows on the same computer), first use your DOS/Win utility FDISK to make the MS Windows partition(s). Leave a part of the hard drive(s) unpartitioned for Linux. You will make and format the Linux partitions during your RedHat installation. Make the MS Windows partition "primary" and "bootable". Install, configure, and test your MS Windows before Linux installation. If you plan to run Linux only, you need just clean hard drive (no partitions) to start with.
It is possible to have only one Linux partition (plus one for MS Windows if you dual-boot). But it is better to have more partitions so you can keep users’ data separate from the rest of the operating system. This way, if something ever goes wrong and you have to reformat and re-install the operating system, you don’t lose the users’ data. (You can however do a Linux re-install without losing the contents of the /home directory that contains all user data if you skip the "re-format" option given to you during installation.)
During the Linux setup, you will be asked to partition the available space on your hard drive(s). There are many possible ways to partition, depending on your hard drive space, requirements, and taste. I like Linux hard drive partitions like this (for a modest total of 2 GB that I dedicated for Linux):
mount point type size
/ ext2 300 MB
/usr ext2 1200 MB
/home ext2 380 MB
swap swap 120 MB

In the above example, I dedicate 300 MB for the root partition that holds the base of the Linux operating system. I give 1200 MB for the mount point that will be visible on my filesystem as the/usr directory and will contain user’s programs (the programs that don’t come with the base operating system and I install later, for example WordPerfect). I dedicate 380 MB for the partition that will be visible as the directory /home and will contain the setting and data of all users on the machine. And I give 120 MB for a "raw" partition for the operating system to use as the virtual memory (extension of the physical, silicon memory on the hard drive, so-called swap). If your kernel is lower than 2.2 (this is the case with standard RH5.2 and earlier), your swap partition cannot be larger than approximately 127 MB. The rule of thumb is that the swap should be about twice the amount of the physical memory (RAM). 120 MB is quite a bit of swap and it is unlikely you should need more. If you think you do need more (e.g. you expect to run custom programs with really large data structures) you might want to create a larger swap partion during the installation (or several smaller swap partitions) or add swap a file(s) later.
2 GB is a lot of disk space and should be sufficient even for users who like having many applications. (This is because Linux applications tend to be slimmer than their MS Windows equivalents). However, if you try to install everything that’s available for Linux on the Internet, you will surely run out of disk space :-) . My experience is that however large the hard drive space, it will get filled and I regret I don’t have more :-) .
If my space on the hard drive is really restricted, I may consider a two-partition setup like this (for a lean 650 MB total dedicated for Linux):
m ount point type size / ext2 600 MB swap swap 50 MB
In this example, I dedicate 600 MB to contain the base of the operating system, applications, and user documents/data, and give 50 MB for the swap partition (for the operating system to use as the virtual memory). The 50-MB swap should be quite sufficient for medium duty operations. The limitation of 600 MB for the operating system, applications and user data means that you will have to be selective as to which applications you install or else you risk running out of hard drive space. Try pressing <F1> when installing the optional software that come on Red Hat CD--it will give you a short description what the software does so you could perhaps decide if you really need it. (Don’t worry too much if you miss something you need, you can install the missing parts later). You can easily finish the RedHat installation with 200 MB free on your Linux partition (out of 600 MB used in this example) if you make reasonable choices. Please note that "bundling together" the root partition "/" and the /home directory will likely save you some disk space, but it is not the safest solution.
It is possible to install Linux on even less disk space than in the example above, but you will have to be even more selective as to what you install.
For a larger available hard drive space, I may consider the following setup (for a comfortable total of 6 GB dedicated for Linux):

mount point type size / ext2 400 MB /usr ext2 2000 MB /usr/local ext2 2500 MB /home ext2 800 MB swap swap 300 MB
Please note that the the mount points can reside on different physical hard drives.
Another consideration when setting up the partitions. Many older BIOSes have the restriction that the boot partition cannot extend beyond the 1024th cylinder on your first physical hard drive. To overcome this limitation, simply make the first (bootable) partition so that it ends before the cylinder number1023 (this makes this partition max approximately 512 MB in size, which is plenty for the "/" root partition). Once Linux boots, the BIOS restriction does not matter any more as Linux can also access the partition(s) beyond the cylinder number1023.

When installing and using Linux, your drives appear as devices with the following names: hda--first IDE drive (stands for "hard drive a", i.e. the master drive on the first IDE interface), hdb--second IDE drive (i.e., the slave drive on the first IDE interface), hdc--third IDE drive (i.e. the master drive on the second IDE interface), hdd--fourth IDE drive (i.e. the slave drive on the second IDE interface). The numbers mean the partitions on the physical drives: "hda1" means the first IDE hard drive (hd a), first partition (1); "hda2" is the first IDE hard drive, second partition; "hda3"--the first IDE hard drive, third partition; (and so on if you have more than 3 partitions on the first IDE hard drive); "hdb1"--second IDE hard drive, first partition (or just "hdb" if it is the CDROM installed as a slave on your first IDE interface). "hdc1"--third IDE hard drive, first partition, etc. SCSI drives have analogous names but start with letters "sd" (="SCSI drive"), followed by the letter indicating the SCSI interface and by the number indicating the SCSI device id. For example, "sda4" means "first SCSI interface, id number 4". If you have an external zip drive attached to your parallel port, it will apear as a SCSI device "sda4" (it works in a SCSI-emulation mode).

10 The MS Windows partition occupies my whole harddrive. Can I shrink/split it without a re-install?

Possibly. There is a utility called FIPS.EXE on your RedHat CD that does just that. Check the directory \dosutils\fipsdocs\on your RedHat CD for documentation. If I were you, I would back-up my essential data before doing anything to the partition. There are also commercial utilities to change the partition size without destroying the content of the partition.
My personal preference is to do a clean re-install of MS Windows on a single, dedicated partition. I leave some space on the hard drive unpartitioned so I can use it later for Linux. My fair division of hard drive space between MS Windows and Linux is 50/50. Linux programs tend to be smaller but they include as a standard components that MS Windows offers only with many thousand dollars of add-ons: e.g., servers (not just clients) for telnet, ftp, http, and mail, several databases, programming lanuages, ...

11 How do I start the installation?

Insert the installation boot diskette into your floppy drive, the RedHat CD to the CDROM, and reboot. If you boot from the CD, insert the RedHat CD into your CDROM drive and reboot.
You may also start the installation from DOS (or real DOS mode under MS Windows), by running EZSTART.BAT which is on my RedHat CD from Cheapbytes.

12 Is the Linux installation difficult?

It was not for me. It seems that for most newbies, it is fairly straight forward and painless. Depending on your hardware and installation choices, it typically takes 0.5 h to 2.0 hours. [Expect longer or possible problems for slow systems with very restricted memory--it took whole night to install RH on my 486-33 MHz with 8 MB memory, the system pausing for 5 minutes at a time appearing to do nothing, yet it installed ok.] However, some newbies reported that the installation was a "total nightmare" to them (hardware problems?). If you encounter problems, my advice would be to install a plain-vanilla system, without struggling with the highest resolution on your fancy video card or other bleeding-edge hardware which you might have. Anything can be added/configured later, after you get more understanding of how things work on your system. Even a re-install is always an option for a newbie (it seems Linux gurus think it is a shame to ever re-install). It seems that many newbies have problems because they specify too high screen resolutions (which may be not supported or supported only with some extra tune-up). Again, it may not be wise to break your whole installation for support of a single device--the support can be added/tuned-up later.
13 I finished the installation. How do I log-in for the very first time?
As root. "root" is the only account that exists after the initial installation (newer installation programs do prompt you to create a regular user account during the installation). Example login:my_machine_name login: root
Password: my_password

In the example above, I typed the word "root" at the login prompt. After that, I entered the password that I chose during the initial Linux installation. The password did not appear on the screen when I typed it (for security).

"root" is a special account with an absolute power over the system, and it is used for system administration. You surely want to create at least one more "user" account later to perform regular (not system administration) work. Read on to learn how to do it.