CS Student Linux User's Guide

From TLUGWiki

Jump to: navigation, search

Contents

[edit] Image:intro64.png Introduction

[edit] About This Guide

This purpose of this guide is to introduce you to Linux and teach you the basics of what you need to know in order to use it effectively. The topics are organised more or less in order of importance and what you will encounter as you start learning Linux. To make this guide as simple as possible and to enable you to learn Linux quickly, the more advanced topics are kept separate.

Please note that this guide is continually being updated and improved. You can check back here and use the Wiki features to see what changed, or you can simply "watch" this article to see what is going on.

Some conventions used in this guide:

  • Text in a fixed-width font are usually commands or keystrokes that need to be typed.
  • Text on a gray background indicates commands typed at the command prompt in a terminal.
  • For the sake of brevity, the command prompt (e.g. [derick@solaris cos213]$) is often abbreviated to #
  • A plus (+) next to the name of a section indicates that it isn't required to know, but will still be useful.
  • A red exclamation mark (!) next to the name of a section indicates that it is really important and you need to understand it well.

[edit] Logging In and Out

Logging in doesn't require much explanation. Just remember that usernames and passwords are case-sensitive. The Linux login screen also allows you to choose a session or "desktop environment", but for now you can leave it at "default" which will load KDE. For more information on desktop environments, see the section on Desktop Environments and Window Managers.

Regardless of which window manager you chose, it should have some sort of "Start menu" containing a "Logout" option. You can also press Ctrl+Alt+Del and select "Logout". (In KDE, pressing Shift+Ctrl+Alt+Del will log you out without asking for confirmation.)

To reboot a machine, choose "Shutdown..." on the login screen and then choose "Reboot". If you happen to be logged in you can select "Reboot" from KDE's logout menu too.

IMPORTANT! Never, ever reboot a machine that is still alive with the reset button (this goes for Linux and Windows) unless there's absolutely no other way of shutting it down. Terminating an operating system without allowing it to shut down cleanly can damage the filesystem. The ext3 and reiser filesystems commonly used on Linux handle unclean shutdowns better, but it is still bad, so don't do it. In Linux it is almost never necessary to reboot when something went wrong – in most cases you can just restart the GUI (X Window System). See the When Things Go Wrong section.

[edit] Image:terminal64.png Linux Commands & Tools - An Introduction to the Terminal

[edit] Why the Terminal? (!)

If you grew up in Windows (like most people using computers today), you may find the concept of typing commands at a prompt rather strange and old-fashioned. But contrary to popular belief, typing commands at a command line prompt can often get things done faster than point-n-clicking around with a mouse. Since you'll be compiling and running your programs from inside a terminal anyway, it makes sense to use the same interface for managing files too. As you'll see, the Linux shell is extremely powerful – infinitely more than the DOS or Windows command shell. Almost everything you'll need to do is possible in the GUI too, but you are strongly encouraged to use a terminal.

Of course, it's your choice whether to take the time to learn the necessary Linux commands, or to point-n-click your way through everything the way you've gotten used to in Windows. It requires a somewhat different mindset, but when you grasp the power of the Linux command line you'll understand why it's considered to be so useful and an efficient way of performing a variety of tasks.

You can start up a terminal by clicking the konsole button on the taskbar. If you're working in KDE, this will start up Konsole. For more information about different terminals, check out section 5.4 Terminals.

You'll be presented with a command prompt that looks something like this (Gentoo-style):

s2123456@b038pc042 s2123456 $

or this (Red Hat-style):

[s2123456@b038pc042 s2123456]$

We will use the Red Hat-style prompt in this guide.

Your username appears before the @, the hostname of the computer after that and finally the name of the current directory (which changes as you navigate to other directories). Type exit (or press Ctrl+D) to close the terminal. The shell (the program that presents you with the command prompt and executes your commands) most commonly used on Linux is called "bash" (Bourne-Again Shell). As I've mentioned, its capabilities are vast ­– entire books have been written on using the shell and scripting in it. If you are interested in its more advanced features, take a look at the ABS Guide (Advanced Bash Scripting guide).

[edit] Image:samba64.png Some Differences from DOS/Windows (!)

  • Linux filenames are case-sensitive, so "fourtytwo" and "FourtyTwo" are not the same.
  • Linux pathnames use a slash (/) as a separator, not a backslash (\) as in DOS/Windows. This is very sensible since the backslash is used to escape special characters just like in most programming languages. (This means that Linux filenames can contain absolutely any characters - including slashes.)
  • The root directory in Linux is simply called "/" (as opposed to "C:\" in DOS and Windows).
  • Linux has no "drive names" like A, C, D etc. – stiffies, CD's and harddisk partitions are mounted on directories in the directory tree. This lets the files on the disk/CD appear as if they are logically part of the normal filesystem and you can access them just like you would any other files on your hard disk. However, you can use an easier way to access stiffies as explained in section 2.5 Working With Disks.
  • The administrator on a Linux system is called "root". Unlike the administrator on a Windows system, root really is all-powerful. Root can delete any and all files and kill any and all processes, no questions asked. While Windows user accounts traditionally have administrator access by default, Linux users are restricted and clearly separated from the root user. This ensures integrity and security of the system.
  • The current directory is not in the path by default. This means that when you want to run a program that is in the current directory, you need to put a ./ in front of the name. For example, if I want to run a program called "prac1" in my cos213 directory, I would type:
[derick@solaris cos213]$ ./prac1
  • Since Linux is a proper multi-user OS, all files and directories belong to some user (who belong to one or more groups) and have access permissions. This is described in more detail in section 2.4.10 chmod – Changing File Access Permissions.

[edit] Terminal Basics

  • Tab completion:
    This is the killer feature that makes working in the terminal a breeze. Whenever you need to type in a filename, all you need to do is type the first few letters and press Tab. If the letters you typed were enough to uniquely identify the filename, it will be completed for you. If not, there will be a beep and if you press Tab again, a list of all files matching the letters you've typed will be displayed.
  • Command history:
    Most shells keep a history of the commands you've typed, so you can press the up and down arrow keys to cycle through your previously typed commands.
  • Output history:
    The terminal keeps a number of lines of the output that has scrolled off the visible area. You can use Shift+PgUp and Shift+PgDn to scroll the output up and down by a page. (In some terminals, like Konsole, Shift+Up and Shift+Down can be used to scroll by a single line.) This is quite useful to see what you did a while ago, or if the output is more than a screen long. You could also use the terminal's scrollbar, of course.
  • Copying & pasting:
    Any text you select in Linux (anywhere) is automatically copied to the clipboard, and you can paste it by clicking the middle mouse button. Very useful for transferring text between a terminal and a text editor, or a browser and a word processor. In KDE you can also use a program called Klipper to keep a clipboard history, so you can access e.g the last 10 things you copy-n-pasted.



[edit] Basic Commands

[edit] Image:ls64.png ls – Directory Listing

Description:
ls is used to list the contents of a directory. The files are colour-coded according to their types:

Blue
Green
Red
Magenta
Teal
Dark green
Cyan
Yellow
White

directories
executable files (e.g. programs, shell scripts)
archives / zip-files
images
media files (audio, video, etc.)
documents (text, PDF, etc.)
symbolic links
device files
everything else


Options:
-l Long listing: Display files in a detailed format, showing permissions, owner, group, file size and date. On some Linux distributions, typing ll is the same as ls -l and will also give a long listing.
-a Show all files: Include hidden files in the listing (files that start with a dot are "hidden" – they aren't displayed by default unless you use the -a option.)
-h Show file sizes in human readable format: This option is used with the -l option to show file sizes in KB or MB instead of bytes.
-t Sort by modification time
-r Reverse the sort order

Note: All commands in Linux allow you to combine options, for example ls -lah will list all files in long format using human readable sizes.


[edit] Image:cd64.png cd – Change Directory

Description:
cd works just like in DOS, except that there must be a space between cd and the directory name. Also remember that the pathname separators are slashes (/).

Typing cd .. will change to the previous level in the directory tree; cd ../.. goes back two levels. ".." denotes the parent directory and "." the current directory. So typing cd . will change to the directory you're currently in (which isn't much of a change ;-).

Typing cd ~ takes you back to your home directory. The tilde character (~) is a special character – whenever the shell sees it, it substitutes the ~ with the path of your home directory. Actually, typing just cd and nothing else will also take you to your home directory. cd - will take you back to the previous directory you were in.

Examples:

[derick@solaris derick]$ cd cos213
[derick@solaris cos213]$ cd /tmp
[derick@solaris tmp]$ cd ~/stuff
[derick@solaris stuff]$ pwd
/home/derick/stuff
[derick@solaris stuff]$ cd -
[derick@solaris tmp]$ pwd
/tmp

The pwd command used in the example shows you what your present working directory is, which is useful if you've lost track of where you are.


[edit] cp & mv – Copying and Moving Files

Description:
cp and mv work more or less the same. You give them a list of source files and a destination. mv is also used to rename files.

Note that you can use wildcards, for example: cp *.txt somewhere.

Options:
-r Recursive: Copy directories recursively, i.e. an entire directory tree. (Note: This option is only available for cp.)
-u Update: Only copy/move files that don't already exist at the destination, or that are newer than existing destination files.
-g Progress: Show a progress bar if the operation is going to take a long time.

Examples:

Copy mozilla1280.jpg to the images directory
# cp mozilla1280.jpg images/

Copy quake3 and all its subdirectories to /opt
# cp -r quake3/ /opt

Move Makefile and all .c and .h files to the cos213 directory
# mv Makefile *.c *.h cos213/

Move a file from /tmp to the current directory
# mv /tmp/et-linux-2.60.x86.run .

Rename a file
# mv foo.pl rename.pl

Note that tab completion comes in really handy for the filename in the second last example. Just imagine typing out something like quake.x11-1.0-i386-unknown-linux2.0.tar.gz or How To Write Unmaintainable Code.html (for which you'd have to escape the spaces with a backslash or put the name in quotes.)


[edit] Image:rm32.png rm – Deleting Files

Description:
The rm command removes files (and directories with the -r option).

Options:
-r Recursive: Delete a directory and all its subdirectories recursively, i.e. an entire directory tree.
-f Force: Don't ask for confirmation.

Examples: Say goodbye to the "tmp" directory:

# rm -rf tmp/

Warning: Be careful with the rm command. When you rm something, it's gone and in most cases cannot be undeleted. When you use wildcards, make sure you know what is going to get deleted. Make sure you are in the right directory, especially when doing something like rm -rf *, which will delete everything in the current directory.


[edit] Image:mkdir32.png mkdir & rmdir – Creating and Removing Directories

Description:
These commands require no explanation. Note that rmdir will only delete a directory if it is empty. The easiest way to delete a directory and all its contents is to use rm -rf dirname, as in the example for rm.


[edit] Image:man64.png man – Getting Help From the Man Pages

The Linux manual pages (commonly called just "man pages") are a collection of documents that describe all Linux commands, programs and functions and their options.

  • To display the man page for ls, type man ls.
  • You can use the cursor keys and PgUp/PgDn to move around.
  • Press "q" to quit.
  • To search for text, press "/" (slash), enter something to search for and press ENTER. All occurrences of the text you searched for will be highlighted. You can press "n" to move to the next occurrence and "N" for the previous.

If you don't know what the man page for a certain command or function is, you can use the apropos command to search for a keyword. For example:

# apropos random
...
srandom [random]     (3)  - random number generator
strfile              (1)  - create a random access file for storing strings
strfry               (3)  - randomize a string
urandom [random]     (4)  - kernel random number source devices
...

apropos displays a list of all man pages whose description contains the keyword. The number in parentheses is the man page section.

If there are two man pages with the same name in different sections (e.g. printf), you need to specify the section before the name:

man 3 printf


[edit] Image:passwd64.png passwd – Changing Your Password

To change your password, simply type passwd. You will be asked for your current password, then your new password and again your new password to make sure you entered it correctly.

IMPORTANT: To change your password in the labs, use yppasswd. This is necessary because your account exists on the server kanagawa and not on the local computer you work on.

You can also use KDE's password changing tool: Use K Menu -> Settings -> Change Password.

IMPORTANT: Don't choose an easy to guess password. passwd will warn you if you attempt to choose a weak password (like a dictionary word or name). Don't write it down and don't let anyone watch you type it in. A password cracker is run daily on the server to see if anyone has chosen a weak password and users whose passwords were easily cracked will be notified. Read passwd's man page for more information and suggestions.


[edit] Image:tar64.png tar – Archiving/"Zipping" Files

Description:
tar is used to create archives of files and directories. In essence it does what WinZip does. tar can create different kinds of archives, for example: A plain tar-file (which is just an uncompressed archive, e.g. "tapebackup.tar"), a gzip-compressed archive (which has the extension ".tar.gz" or ".tgz", e.g. "prac4.tar.gz") and a bzip2-compressed archive (which has the extension ".tar.bz2" or ".tbz2", e.g. "MPlayer-0.90rc3.tar.bz2").

Note that filename extensions don't really matter – they're only there to help you and certain programs to know what type a file is without having to look at its contents.

Compressed archives made with tar are often called "tarballs".

Usage: tar [options] archive-name filename1 [filename2, ...]

Note that the filenames may contain wildcards or be directories. You also don't need to use a "-" to specify the options, so tar czf works the same as tar -czf.

You are expected to submit your pracs and assignments as gzip-archives, so most of the time you'd use tar as follows:
tar czf somefile.tgz file1 file2 ...

Options:
-c Create an archive
-x Extract files from the archive
-t List files in the archive
-z Specify that the archive is a gzip-archive
-j Specify that the archive is a bzip2-archive
-f filename Specify the filename of the archive
-v Verbose: List the files being processed
-C dir Extract files to the specified directory

Examples:

Create a gzip-archive named "prac1.tgz" containing the files "prac1.C" and "Makefile"
# tar -czf prac1.tgz prac1.C Makefile

Create an archive of the "cos213" directory and all its subdirectories
# tar -czf cos213-backup.tgz cos213/

Archive all .C and .h files and the images/ directory, and list the files being archived
# tar -czvf proj-0.7-beta.tgz *.C *.h images/

Extract an archive
# tar -xzf NVIDIA_GLX-1.0-4191.tar.gz

Extract a specified file (README) from an archive
# tar -xzf NVIDIA_GLX-1.0-4191.tar.gz README

Extract a bzip2 archive to a specified directory (/tmp)
# tar -xjf feather.bzip2 -C /tmp

List the files in an archive (the -v option gives more details)
# tar -tzvf gentoo-portage.tgz


[edit] Image:du64.png du – Disk Usage

Description:
The du command shows how much space is used by files/directories.

On your lab account, it is important to check your disk space usage with du regularly so you can clean up your home directory before you exceed your quota and are prevented from logging in.

Options:
-h Display sizes in human readable format (e.g. in KB, MB, etc.)
-s Summarise: Display only a total for each directory, instead of the size of every file
-c Display a grand total

Examples:

Display the disk usage of the "mplayer" directory and its files
# du -h mplayer/

Display your home directory's disk usage (without displaying all the file sizes)
# du -hs ~

Display the current directory's disk usage
# du -hs

Display the sizes (in bytes) of all the files and directories in the current directory, sorted by size, and a total
# du -sc * | sort -n

Like the above, but include hidden files ("dot"-files)
# du -sc .[^.]* * | sort -n


[edit] chmod – Changing File Access Permissions

Description:
chmod changes the file access permissions of the specified file(s).

An Introduction to File Access Permissions:
Before we get to the usage of chmod, an introduction to file permissions is required. Here's an excerpt from a long file listing (done with ll in my home directory), which shows some permissions:

permissions     user     group       size    date/time  filename    
-rwxr-xr-x    1 derick   users         152 Feb 11 11:14 arg.pl
-r-x------    1 root     root         1277 Feb  6 09:16 beep.sh
-rw-r--r--    1 derick   users         315 Feb 11  2003 test.html
-rw-r--r--    1 derick   users        3985 Nov 28 11:46 wtf.png
drwxr-xr-x    2 derick   users        4096 Feb  7 08:08 csslug

The first column contains the file access permissions. If the first character is a 'd' then the entry is a directory. The next 9 characters indicate read, write and execute permissions for three groups of users: The owner of the file, other users in the file's group and all other users. The third column shows who a file belongs to and the fourth column shows what group the file is part of (usually this is the group to which the user belongs).

As you can see, all the files belong to me except beep.sh which belongs to root. To explain the access permissions, lets take the first file (arg.pl) as an example. The first group of permissions (rwx) indicates that I have read, write and execute permissions on the file. This means I can view the contents of the file, I can modify it and since it's a Perl script, I can also execute it. The second group of permissions indicates that other users in the file's group (the users group) can read and execute the file, but they cannot write to it (or delete it). The same goes for the third group of permissions applicable to all other users on the system.

The second file (beep.sh) can only be read and executed by root. All other users have no permissions to access that file. (Keep in mind that no matter who owns a file and what its permissions are, root can always access or delete it, or change its owner and permissions.) The third file (test.html) is readable and writable to me, but only readable to everyone else. This is the default when files are created. You may wonder whether this means that other users can read your files. That depends on the permissions on your home directory. (To check the permissions on your home dir, type ll -d ~.) Generally, your home directory will have read, write and execute permissions only for you and no-one else (drwx------). This means that no-one else (except root) can access or change anything in it, or even list the files it contains. For example:

[derick@solaris derick]$ ll -d ~
drwx------   28 derick   users        4096 Feb 11 20:05 /home/derick

It is important to note that directories must always have both read and execute permissions set to be accessible. If you remove execute permissions on a directory, its contents cannot be listed (although they can still be accessed if it has read permissions).


Usage: chmod's options can be pretty complex but we'll only look at its basic usage:

chmod [user type][operator][permissions] file1 ...

user type is one or more of the following letters:
u: the user who owns the file
g: other users in the file's group
o: other users not in the file's group
a: all users

If the user type is omitted the permissions are applied to all users.

operator is one of the following:
+: adds the specified permissions to the existing permissions of the file
-: removes the specified permissions
=: causes the specified permissions to be the only permissions that the file has

permissions is one or more of the letters r, w and x (read, write and execute).

chmod has the -R option that will recursively change permissions on files and directories.

Examples:

Remove execute permissions for all users
# chmod a-x screenshot1.png

Remove read and write permissions for everyone but yourself
# chmod go-rw world_domination_plan.txt

Same as the previous command, just simpler (sets rw permissions for the user only)
# chmod u=rw world_domination_plan.txt

Grant read access to everyone
# chmod +r Snarfer.java

Grant read/write access to everyone on all files and dirs in cos213proj/
# chmod -R +rw cos213proj/

Multiple permission sets can be separated by commas.
The following removes execute permissions on everything in the "songs" directory,
but adds them back to directories only (which need them to be accessible)
# chmod -R -x,+X songs/

Note: When copying files from CDs or Windows FAT partitions, the permissions are always set to "rwx" for everyone ("r-x" for read-only files). This is because the FAT filesystem used on disks and non-NTFS Windows partitions don't support permissions or ownership (there is essentially no file-level security on a FAT-based Windows). This isn't really a problem, but you may want to chmod -x such files that aren't actually executable. The last example above is an efficient way of removing these unnecessary execute permissions on a whole tree of files (for example, when you've copied your music collection from a FAT partition).


[edit] cat & less – Displaying Files

Description:
cat and less can be used to view files.

The easiest way to view a file is to type: cat filename.

You can use the -n option to number each line, e.g.: cat -n foo.C

For longer files you can use less. less shows a screenful of the file at a time and you can move up and down with the cursor keys and PgUp/PgDn. To quit viewing the file press "q". You can also press "/" (slash) and type in a word to search for just like in the man pages (in fact, the man pages are displayed using less). "n" finds the next occurence of the word and "N" finds the previous one. Pressing "<" skips to the beginning of the file and ">" to the end.

The less command was doubtlessly inspired by the more command. less works more or less like more, but it has more features, which in this case disproves that less is more.


[edit] Image:find64.png locate, which & whereis – Finding Files and Commands

locate can be used to find files whose names contain a specified string. For example:

[derick@solaris derick]$ locate foobar
/home/derick/images/screenshots/Windows goes foobar again.jpg
/home/derick/linux/ati_foobarness.txt

The -i option can be used to search case insensitively.

which is used to find the full path of a Linux command or program. For example, to find out where kpoker is:

[derick@solaris derick]$ which kpoker
/usr/kde/3.5/bin/kpoker

whereis finds not only Linux commands, but also source and manual page files for a command. For example:

[derick@solaris derick]$ whereis whoami
whoami: /usr/bin/whoami /usr/share/man/man1/whoami.1.gz
           [binary]               [man page]

[root@solaris root]# whereis mybitches
mybitches:

Clearly, there are none of the latter on my system ;-)


[edit] Image:floppy64.png Working With Floppies, CDs & USB Devices

Note: For the purposes of this guide, we will refer to 3.5" disks (which some people call "stiffies") as "floppies".

Description:
As mentioned in the section about differences between Linux and Windows, the contents of removable media like floppies, CDs and USB flash disks are not automatically visible through drive letters and need to be "mounted" first. When a disk is mounted onto a directory (usually one of the directories in /media or /mnt), it becomes logically part of the directory structure and you can access the files on it just like any other on the hard disk. A disk that has been mounted must always be unmounted to ensure that any changes made to it are committed.

Mounting and unmounting is a foreign concept to most people who are not familiar with Linux. If you prefer to access disks in the Windows way, you can use the mtools commands described below.

You have three options when it comes to accessing removable media:

  1. Use mtools:
    The mtools commands allow you work with floppies like in DOS, meaning you don't have to mount/unmount them and you access them through the drive letter "a:". The mtools commands are just like the DOS commands, except they all start with "m": mcd, mdir, mcopy, mdel, mmove, mren, mmd, mrd. To see a complete list of mtools commands, type mtools in a terminal. For example, to copy a file: mcopy cos213-prac1.tgz a:
  2. Keep the age old Unix tradition of mounting/unmounting disks yourself:
    To mount a floppy: mount /mnt/floppy
    To mount a CD: mount /mnt/cdrom
    To mount a USB flash disk: mount /mnt/usb
    After mounting, a floppy is accessed through the directory /mnt/floppy and a CD through /mnt/cdrom. (These directories are called "mount points".) The argument given to mount specifies the mount point of the device containing the disk to be mounted. Alternatively, you can also specify the device to mount instead of the mount point, e.g. mount /dev/fd0 or mount /dev/cdrom. USB storage devices are emulated as SCSI disks and are usually called mount /dev/sda1 or mount /dev/sdb1. After you've finished reading from or writing to a disk, it must be unmounted:
    Floppy: umount /mnt/floppy
    CD: umount /mnt/cdrom
    USB: umount /mnt/usb
  3. Use KDE and the Konqueror file manager:
    In KDE, you can mount/unmount a floppy by right-clicking on the floppy icon on the desktop and choosing "Mount" (or "Unmount"). A little green triangle will appear on the icon indicating that the device is mounted. The same goes for CDs and flash disks. From there on you can use a terminal or the file manager to manage files like normal. Remember to unmount!

Important:

  • When you've made modifications to a floppy it is critical that you unmount it. Linux caches aggressively and almost always new or modified data isn't written to the floppy immediately. When you unmount the floppy, all outstanding changes are committed.
  • When a CD is mounted it cannot be ejected using the eject button. You must first unmount it, or use the eject command which automatically unmounts the CD. You can type eject -t to close the tray (if leaning over to press the button is just too much effort...)
  • Some Linux distributions are configured to automount CDs and flash disks. In that case, a CD-ROM of flash disk icon will appear in the taskbar and you can use it to "safely remove" the disk.

Note: For more information about USB devices, see the Working With USB Devices guide.


[edit] Image:terminal64.png Running Programs From the Terminal

[edit] Programs in the Current Directory

As mentioned in the section about differences between Linux and Windows, the current directory is not in the path. This means that if you want to run a program in the current directory, you need to prefix it with ./

To repeat the example used previously, if I want to run a program called "prac1" in my cos213 directory, I would type:

[derick@solaris cos213]$ ./prac1

The dot indicates the current directory, and the slash is the directory separator (this is to distinguish it from ".prac1" which is a valid filename).

At first glance this might seem awkward and pointless, but there are good reasons for this. If you consider the immensely large collection of Linux commands and programs (on my system there is nearly 2300), it is not so difficult to come up with a name for your own program that is already used. To protect against any ambiguity, the current directory is not part of the path.

[edit] Elementary Job Control (+)

Unix, the ancestor of Linux, supported multitasking before graphical user interfaces were even dreamed of. You could run several programs (or "jobs") at the same time on the same console and switch between them using a feature called job control. The simplest and most common use of job control is running a program, putting it in the background and continuing to use the shell. Here's an example:

Suppose you run an application like kpdf (to view PDF files) from within a terminal:

[derick@solaris derick]$ kpdf
  

kpdf pops up, and when you look at the terminal you'll see the cursor but no prompt. It doesn't respond to input until you close kpdf. However, you can suspend kpdf by pressing Ctrl+Z in the terminal, which gives control back to you:

[1]+  Stopped                 kpdf
[derick@solaris derick]$

When you look at kpdf now it is suspended and doesn't respond. Now type bg in the terminal to allow kpdf to continue running in the background:

[derick@solaris derick]$ bg
[1]+ kpdf &
[derick@solaris derick]$

The ampersand (&) indicates that kpdf is running in the background and you can continue using it like normal.

If you know beforehand that you want to run a program in the background and continue working in the terminal, you can add an ampersand (&) to the end of the command line:

[derick@solaris derick]$ kpdf &
[1] 1932
[derick@solaris derick]$

The line that's printed out tells you that this is the first program started in the background ([1]) and what the process ID of that program is (1932). This will obviously be different on your system.

You can do the same with programs running inside the terminal, for example the vi editor:

  1. Type vi in a terminal. You'll be presented with the intro screen.
  2. Press Ctrl+Z to suspend it.
  3. Type bg to allow vi to continue running in the background. (This isn't strictly necessary for something like vi because it doesn't need to actually do something in the background, but for other programs that do any processing it is required.)
  4. You can now go on and use the terminal, and whenever you want to switch back to vi you type fg to bring it back to the foreground.


[edit] Image:ksysguard64.png Process Management

[edit] ps & top – Listing the Running Processes

Description:
ps lists the processes running on the system. top displays a continually updated list of processes (press "q" to quit top).

Options for ps:
a Display all processes, including those of other users (without this option, only processes belonging to you are displayed)
u Display user-oriented format. Basically this displays information like username of owner, CPU and memory usage, resident stack size, etc. for each process
x Together with "a", list all processes, including those without a controlling terminal (without this option, only processes that have been started from a terminal will be displayed)
f The "forest" option: Display the process listing as an ASCII-art tree

Note that the above options are not preceded by a - (minus). ps has many different options, some of which start with a minus and some that don't. There are many other options, but the abovementioned ones are the most commonly used. You can check out the man page for more details.

One of the most useful ways to use ps is ps aux. In fact, this is probably the only way you'll need to use it. You could also try ps auxf which nicely displays the process hierarchy in tree format.

When running top, the following are some of the keys can be used to customise the display:

Options for top:
h Display help
q Quit
M Sort by memory usage
<, > Sort by the previous or next column
s Change the update interval
u Display only processes belonging to the specified user
W Save the current configuration


[edit] kill & killall – Sending Signals to a Process

Description:
kill and killall are used to send signals to processes. By default the TERM signal is sent which will terminate a process. The most common use of kill and killall is to, well, kill processes that have stopped responding or are misbehaving. killall differs from kill in that you specify the name of the process you want to kill, and it will terminate all processes with that name. Signals are not used only for killing, but also for inter-process communication where one process can to some extent control another by sending different kinds of signals. A program can set up a signal handler to "catch" certain signals and act upon them. Certain signals cannot be caught (like KILL), so a program that receives such a signal will always terminate.

Usage:

kill [-s signal] process_id ...
killall [-s signal] process_name ...

In order to find out what the process ID (PID) or name is of the program that you want to kill, you need to use ps as described above. A list of signal names can be found in /usr/include/asm/signal.h, but you probably won't need to use any other than the default TERM signal, or perhaps KILL when a process won't respond to TERM.

Examples:

Send the TERM signal to process 1984 and hope it dies...
# kill 1984

kill -9: Send the KILL signal. Use with caution. One doesn't just throw around the KILL (9) signal for fun.
It kills without mercy and without giving a process any opportunity to exit gracefully.
# kill -9 10372

Kill all instances of bash (including the one you're typing in)
# killall bash

Send the HUP signal to all instances of artsd (HUP usually instructs a program to restart itself
or reread its config files)
# killall -s HUP artsd


[edit] Image:home64.png Your Linux Account

[edit] Managing Your Home Directory – Doing Housekeeping

When working in the Informatorium labs, your Linux home directory resides on a server called kanagawa (kanagawa.up.ac.za, to be precise), along with more than 1000 other users' home directories. Disk space is limited and therefore you should make sure that you don't use too much space.

It is your responsibility to keep your home directory clean. You should check your disk usage periodically (every week or so) – see Disk Usage.

Here are some tips for managing your home directory:

  • Use tar to archive old programs and source code. Keep the archive and delete the old files.
  • After you've extracted an archive, delete it. It's usually unnecessary to keep the archive lying around when you've got its contents.
  • Set your browser's cache to at most 20 MB. If you use different browsers, try keep the total size of their caches to about 20 MB. To set the cache size in...
    Konqueror: Settings -> Configure Konqueror... -> Cache. Change "Disk cache size" to 20480.
    Firefox: Edit -> Preferences... -> Privacy -> Cache. Change the value in the textbox to 20.
    Opera: File -> Preferences... -> Network -> Network -> History and cache. Change "Disk cache" to 20480.
  • Don't keep movies and MP3s in your home directory. Such files take up space – lots of it. The same goes for BMPs. Save them in some sensible format like PNG or JPG. Be aware that if the server administrators find illegal content in your home directory, it will disappear.
  • Empty your Trash directory. Or just don't use it at all – delete files in Konqueror using Shift+Delete.
  • Try not to write programs that write to disk in infinite loops. Linus Torvalds, creator of Linux once said: "We all know Linux is great... it does infinite loops in 5 seconds." That's about how long your account will last if you do this.
  • The configuration of programs is usually stored in files or directories starting with a dot, for example .kde. These so-called dot-directories are "hidden" – they don't show up in a directory listing unless you use the -a option. Almost every program you use will create configuration files in your home directory and over time this could take up lots of space. If you wonder where all your space is going, one of the first places to look is in the .kde directory. Use du -hs .kde to see how much space it's taking up and du -h .kde to see how much space each subdirectory in .kde takes up. In particular, .kde/share/thumbnails may be a culprit. In addition, if you've tried out different window managers and decided to stick with one, delete the others' config files.
  • If you use a debugger: When a program you've written causes a segmentation fault (of which you'll have many), a core dump may be generated. A core dump is a snapshot of your program's state when it crashed and could be a few MBs large. Try disabling core dumps in the debugger or be sure to clean them up afterwards (nobody likes a messy home directory full of core dumps...) Cores usually have names like .core-xxxxx.

[edit] Image:remote64.png Accessing Your Account Remotely (+)

[edit] Secure Shell (SSH)

You can access your account on kanagawa from any computer with a secure shell (SSH) client. For example, if you have an Internet connection at home you could log in on kanagawa with your account using SSH. Suppose I'm at home and want to edit some files on my home directory on kanagawa:

[derick@solaris derick]$ ssh dswanepoel@kanagawa.up.ac.za
dswanepoel@kanagawa's password: [Enter password]
Last login: Thu Feb  6 16:02:46 2003 from roadkill.cs.up.ac.za
[dswanepoel@kanagawa dswanepoel]$

Now I'm logged in on kanagawa (notice how the prompt has changed) and I can edit files and run programs just as if I was sitting in the lab. Type exit or press Ctrl+D to log out.

When you are logged in via secure shell, all transmissions are encrypted. It is also possible to run GUI applications over an SSH connection (when using a dialup connection from home it's not very practical, but within the university's network it works fine). When you run a GUI application like SciTE or Konqueror via SSH, it actually runs on the remote system but the window is rendered on your local system. (This is unlike running a program over a Windows network where the executable is simply loaded into memory and runs on your local system.) In fact, it is possible to run KDE and all supporting applications remotely over a LAN connection with virtually no slow down at all.

There are SSH clients for Windows too, so you can still access your account from home if you can't install Linux there. PuTTY is a nice Windows SSH client, which you can download from http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html . Note that you can't run GUI apps remotely on Windows, unless you've got an X server for Windows like Cygwin's X.

[edit] Secure Copy (scp)

Description:
Secure copy (scp) allows you to copy files between computers on a network. In other words, you can copy files from your home directory on kanagawa to your computer at home and vice versa. This is extremely useful for when you forgot to copy a practical's source code on a disk to take home (or if your disk has died a tragic premature death). It's a much easier way to transfer files between varsity and home than e-mail or unreliable disks. There is a Windows client called "pscp" which is part of the collection of PuTTY tools.

Usage: In it's simplest form, an scp command looks as follows:

scp [options] source destination

"source" and "destination" have the following format:

[[user@]host:]filename

scp makes various assumptions if you omit certain parameters:

  • Username: Use the current user's username
  • Username and hostname: Assume the file is on the local system
  • Full path to filename on remote host: Assume the filename or partial path is in the user's home directory
  • Destination path/filename: Copy the file to the user's home directory
Options:
-r Recursively copy entire directories
-C Enable compression

Examples:

Copy a file from my local system to the /tmp directory on physlab7 using the root user:
# scp bash_quotes.txt root@physlab7.up.ac.za:/tmp

Copy a file from my home directory on kanagawa to the current directory
(note that because I don't specify the full path to the remote file,
scp assumes it's in my home dir on kanagawa):
# scp derick@kanagawa.up.ac.za:world_domination_plan.txt .

Copy a file from my local system to kanagawa. Since the remote path doesn't
start with a "/" it is assumed to be a subdirectory of derick's home directory:
# scp proj-0.7-lumberjack.tgz derick@kanagawa.up.ac.za:cos213/

Copy some files to baobab. Since the remote username is omitted it is assumed to be
the current user, and since the remote path is omitted it is assumed to be
that user's home directory on baobab:
# scp *.jpg *.png baobab.up.ac.za:

Copy the entire apps dir on 137.215.45.107 using user derick to root's home
directory on andromeda. Note that there are 3 different machines involved:
The one the command is issued from, the source and the destination:
# scp -r derick@137.215.45.107:/tmp/apps root@andromeda.up.ac.za:

[edit] Image:compiling64.png Compiling Programs

[edit] The GNU C Compiler and C/C++

[edit] Discussion

The compiler(s) used on Linux are part of the well-established GNU Compiler Collection (GCC). This includes gcc (for compiling C programs) and g++ (for C++ programs) which are the compilers you'll be using. (For the rest of this guide I'll refer to both these compilers as "gcc".) gcc compiles the source code of your programs into object files (which have a .o extension) and then links them together into an executable file (also called a "binary").

[edit] Filename Extensions and Execute Permissions

Note that executables on Linux don't have a .exe extension – in fact, they generally don't have any extension. Linux does not identify files by their extensions (like Windows) but by their contents, so it doesn't really matter what you call a file. As long as a file is executable, you can call it something.blah and it will still run when you type ./something.blah. However, if an executable does not have execute permissions it won't run. You can see whether a file has execute permissions by doing a directory listing. If the name is bright green, then it has execute permissions. (If you do a long listing (ls -l) the permissions column should contain an 'x'.) If for some reason a program does not have execute permissions, you can give it those permissions using the chmod command, e.g.: chmod +x program. When you compile a program with gcc it automatically gives it execute permissions.

C source files usually have a .c extension. Extensions for C++ source files vary, but the most commonly used ones are .cpp, .C or .cxx. (The unofficial standard for COS213 is to use .C) See gcc's manpage for more details.

[edit] Other Compilers

Since your programs will be compiled with gcc when they're marked, you are seriously discouraged from using any other compiler. Avoid Cygwin's version of gcc unless it's impossible to install Linux on your computer. Your programs may compile under Cygwin but there's no guarantee it will run correctly. Even a simple COS213 assignment that works perfectly in Linux can segfault and do weird things in Cygwin, resulting in students losing marks and other atrocities. Don't even think about coding in Windows and compiling with Borland or Microsoft's compiler – not only do they produce Windows binaries which cannot run on Linux, but there is also no guarantee that your code will even compile with gcc.

[edit] GCC 3 vs. 2

Very old versions of Linux (released before 2002, like Red Hat 7.3) use an older version of gcc (2.95) that is not fully compatible with the current version (3.x). This means that programs that compiled with gcc 2.x may not necessarily compile with gcc 3.x. Unless you need to use an old version of Linux with gcc 2.x, you don't have to worry about this section. However, you may see some code on the Internet which still follows the old gcc 2.x style, so it is useful to be aware of the following two most important changes:

  • Deprecated headers: In the past certain header files such as iostream.h, tree.h, etc. were included using:
    #include <iostream.h>

    In gcc 3.x the .h extension is dropped for these headers, so the above statement becomes:

    #include <iostream>

    If you use one of these headers in the deprecated way, gcc will print a nice, long warning. (You would typically use the iostream header for functions like cout.)

  • Namespaces: If you've included iostream as specified above and you get errors like `cout' undeclared, you probably forgot to use the appropriate namespace. When using cout and related iostream functions you should add the following after the includes:
    using namespace std;

To see what version of gcc you have, type gcc --version.


[edit] Using GCC

Syntax:
The following is the most common way of using gcc:

C:
gcc [options] inputfiles -o outputfile
C++
g++ [options] inputfiles -o outputfile

where inputfiles are source and/or object files and outputfile is the name of the executable to be produced. It doesn't matter in which order you specify the options, input files and output file. Here is a very simple example:

g++ matrix.C -o matrix
Options:
-o filename Specify the name of the output file, which will be an executable unless the -c option is used
-c Compile the source file(s) but don't link them into an executable. This will produce an object file (.o) for each source file
-On Optimise. The value of n controls the level of optimisation, which ranges from 0 to 3. Compiling your program with -O3 will compile it with the highest level of optimisation. -Os optimises for size (makes the binary as small as possible). -O0 disables optimisation. (Note: The -O option is "minus Oh", not "minus zero".)
-W Enable all warning messages (a good option to use to make sure your code doesn't do potentially dangerous or questionable things)
-Wextra Enable extra warnings that are not generally serious, but may want to be caught. (-Wextra is the same as the old -W option.)
-w Don't display warning messages
-lfoo Link the program against an external library called libfoo. For some math functions you may need to link your program against libm, for example: gcc vector.c -lm -o vector
-g Generate debugging information. This is necessary when you want to debug your program with a debugger like gdb or ddd. (It's usually a good idea to disable optimisation when debugging a program because certain optimisations can reorder instructions, which can be very confusing.)
-MM Output the dependencies for the given source file (doesn't compile anything). This is very useful for when you're creating a Makefile

For more information (especially on the topics of optimisation and warnings) see gcc's manpage.
For an explanation of the purpose of the -c option see the Writing a Makefile section.


[edit] Writing a Makefile

Discussed in a separate section by Jaco Kroon.


[edit] Image:java64.png Some Notes About Java (+)

  • If you install the Java SDK (or JDK) you do not need to also install the Runtime Environment (JRE) since it is included in the JDK. If you use a Linux distribution like SUSE, Mandriva or Fedora, you need an RPM package for Java which will have a name like j2sdk-1_4_2_03-fcs-linux-i386.rpm. To install an RPM package, enter the following commands in a terminal:
    su -
    [Enter root's password]
    rpm -ivh /some/path/package-name.rpm
  • IBM produces a Java compiler called "Jikes", which is an excellent compiler. It is several times faster than Sun's compiler and can produce smaller and often faster bytecode. Due to incremental compiling it can compile an entire project consisting of several Java files in under a second. Jikes gives very useful error messages and can even suggest corrections for misspelt variable names. Jikes is also available for Windows. Check out IBM's Jikes Project homepage.
  • Installing the JDK automatically sets the infamous classpath. To set the classpath for Jikes, edit /etc/profile (or .bash_profile in your home directory) and add the following line before the one that reads export PATH:
    JIKESPATH=.:/usr/java/j2sdk1.4.2_03/jre/lib/rt.jar

    Now add the JIKESPATH variable to the export line, e.g.:

    export PATH JIKESPATH

    NB: Your path to the JDK will most likely be different from the above example. To find out what the correct path is, use the locate program to find rt.jar:

    [derick@solaris derick]$ locate /rt.jar
    /opt/blackdown-jdk-1.4.2.03/jre/lib/rt.jar
    

    If there is more than one match, choose the one with the latest version number. If nothing shows up, run updatedb (as root) and do the locate again when it has finished.


[edit] The Graphical User Interface (GUI) (+)

The following is a brief explanation of the Linux GUI and how it works.

The Graphical User Interface (GUI) of Linux consists of four parts: A set of programs called the "X Window System" (commonly referred to as "X"), a desktop environment, a window manager and user applications.

[edit] The X Window System

The X Window System forms the base of the Linux GUI. The desktop environment, window manager and user applications are all GUI programs that run on top of X. X provides low-level graphics operations which GUI programs use to draw buttons, interact with the user, etc. The desktop environment, window manager and X are user-space applications – they are not part of the kernel as is the case with Windows. This necessarily makes them slightly slower, but with the advantage of increased flexibility and overall stability of the system. If the window manager or X crashes it seldom affects the kernel, and since they're just normal programs they can be restarted without rebooting the system.

X is based on a client-server architecture, where a computer runs an X server and all GUI applications are X clients. X is network-enabled, meaning that the server and clients may be on different computers. This allows one to run GUI applications over a network, where the application runs on one computer but displays on another.

[edit] The Desktop Environment

A desktop environment is a set of programs that provide things such as the desktop, taskbar, clock, etc. The two most common desktop environments are KDE and GNOME, and they provide many supporting applications such as browsers, e-mail clients, calculators and image viewers. Some desktop environments do not have their own supporting applications such as browsers and only provide the basics. The programs of each desktop environment can be used on any other – for example, you can use KDE's Konqueror browser in Gnome and Gnome's Evolution e-mail client in KDE.

The desktop environment also provides the third component of the Linux GUI: the window manager.

[edit] The Window Manager

A window manager is an application that draws the titlebar and border around windows (called window decorations), and the desktop. It interacts with the taskbar to allow the user to switch between applications (Alt+Tab), minimize or maximize them, etc. Some window managers allow you to change the style of the window decorations, from traditional old UNIX desktops to Windows to Mac OS X.

This section describes some of the features of the KDE window manager, most of which are common to almost all Linux window managers.

[edit] Multiple Desktops

Almost all Linux window managers allow you to have more than one desktop. Usually there are four "virtual desktops" (KDE lets you to have up to 16), so when one of them becomes cluttered with windows you can switch to a new, clean one. On the taskbar you should see a grid with four blocks, numbered 1 to 4. Clicking on one of them switches to that desktop. In KDE you can also switch to the next or previous desktop by pressing Ctrl+Alt+Right or Ctrl+Alt+Left. Holding Ctrl and pressing Tab will cycle through the desktops from 1 to 4. You can configure the taskbar to show only the programs on the current desktop (the default) or to show programs from all desktops.

[edit] Window Options

Right-clicking on the titlebar of a window (or its entry in the taskbar) brings up a menu of window options. Among these options are the following useful functions:

  • Advanced > Keep Above Others: When this option is enabled the window will always remain in the foreground, on top of all other windows on the current desktop. This is very useful for doing this like keeping a calculator on top of your editor while doing a lot of calculations. (This option may be called "Always on Top" in other window managers.)
  • To Desktop: This option brings up a submenu where you can choose to send the window to a different desktop. Choosing "All Desktops" causes the window to appear on all desktops.
  • Sticky: Choosing "All Desktops" on the "To Desktop" menu makes a window "sticky," which means that it appears on all desktops. (Depending on KDE's configuration there may be a little pin icon on the left side of the title bar right next to the application icon which fulfils this function.)

KDE 3.5 also provides the following useful options:

  • Advanced > Window Shortcut: This option allows you to define a keyboard shortcut for a specific window. For example, you can define the shortcut Win+E for your editor. Pressing Win+E will then take you to the editor window immediately. This can be much more convenient than using Alt+Tab to cycle through all the windows or using the taskbar.
  • Advanced > Special Application Settings: This option allows you to define custom window settings for an application, such as forcing it to always open on a certain desktop, specifying a default window size, setting a window shortcut, etc.

[edit] Copying and Pasting

Linux allows you to paste selected text with the middle mouse button. Any text you select with the mouse is automatically copied to the clipboard and can be pasted by clicking the middle mouse button (or by clicking the left and right buttons together). This goes for absolutely any text, anywhere. You can paste text from a terminal into a text editor, or from a browser to a terminal, for example. In KDE you will find a little clipboard applet in the system tray that keeps track of the last few selections. If you click on it you can choose a previous selection from its history to paste.

[edit] Locking the Screen

If you need to leave your workstation for a moment and you're concerned about privacy and security (which you should be, especially in the Informatorium), it's a good idea to lock the screen. In KDE you can do this by pressing Alt+Ctrl+L, or by click on the K-Menu and selecting "Lock Session". This will start up a screensaver which will prompt for your password when interrupted.

IMPORTANT! Don't leave your workstation locked for too long. Going on lunch for an hour with your workstation locked is inconsiderate towards the other users of the labs. If you stay away too long some equally inconsiderate person will come and reboot it into Windows anyway...


[edit] So Many Browsers and Editors! Suggestions on Which Programs to Use

One of Linux's distinguishing features is the freedom and choice it provides. There are usually several different applications of the same kind available, whether it be text editors, browsers, mail clients, MP3 players or terminals. This vast diversity may be confusing if you are new to Linux and the open source world, especially if you are used to Windows where lots of decisions are made for you. This section aims to provide some guidance in choosing certain programs from the host of possibilities. Obviously it's subjective to some extent, and remember that the choice is always yours. Use whatever works best for you.

[edit] Text Editors

[edit] Image:scite48.png SciTE

SciTE is a fast, lightweight editor for both Linux and Windows. It has a lot of useful features, including:

  • Syntax highlighting for almost any conceivable language (i.e. C/C++, Java, HTML, XML, Perl, even VB and C#)
  • Code completion
  • Compiling, building with makefiles and running programs
  • Error indicators and the ability to jump to error lines
  • Code folding (contracting / expanding functions)
  • Regular expression-capable search and replace
  • Fully customisable config files for the advanced user

SciTE is included on the Computer Science CD and is installed on Linux and Windows in the labs. Check out the SciTE page for installation instructions, screenshots and a command reference.

SciTE's homepage: http://www.scintilla.org/SciTE.html
New versions can be obtained from http://www.scintilla.org/SciTEDownload.html

[edit] Image:kate64.png Kate

Kate is the KDE Advanced Text Editor. It has many of the same features as SciTE, like extensive syntax highlighting (including support for Quake, Wolfenstein and Half-Life config files!), code completion and quite a few of its own neat features:

  • File list
  • Built-in terminal
  • Project management plugin

Kate has pretty good integration with KDE (a very strong feature of KDE that is continually improving) and can be embedded in the Konqueror browser, for example. Kate is very configurable and has a good configuration interface which is missing in SciTE. It is easy to create a new colour scheme for "deep hack mode" (black background), for example.

[edit] Image:kdevelop64.png KDevelop

For larger projects, KDevelop is a full-featured IDE that supports project management, build systems and integration with Qt Designer for creating GUI applications. KDevelop uses Kate as an editor component, but adds the following features, among others:

  • Symbol lookup with ctags (allows you to right-click on a function and choose "Go to definition" or "Go to declaration" – essential in large projects)
  • Integrated version control (full CVS support, partial SVN support as of version 3.3.x)
  • File templates for every language
  • Documentation browser

[edit] vi and Emacs

These are the two heavyweight text-based editors in the Unix/Linux world. The following quote describes them well:

Real Programmers consider "what you see is what you get" to be just as
bad a concept in Text Editors as it is in women. No, the Real Programmer
wants a "you asked for it, you got it" text editor -- complicated,
cryptic, powerful, unforgiving, dangerous.

Both vi and Emacs are extremely powerful, and although they are harder to use than GUI text editors, they have most of the features of even the most powerful IDEs.

Advantages of vi:

  • vi is almost guaranteed to be on any Unix / Linux system you'll encounter
  • It's a text-based editor, so it's blindingly fast and perfect for editing files remotely
  • It has syntax highlighting for everything. If vi doesn't have syntax highlighting for something, it isn't worth knowing about
  • vi dates back to 1985, so it's been tested and tried with literally millions of lines of code and is stable as a rock

Advantages of Emacs:
Emacs has many of the advantages of vi: It's pretty standard too, fast, has a graphical counterpart and has extensive syntax highlighting. Emacs is more than a text editor, however. Some people say, "Emacs is a great operating system. It just doesn't have all the neat programs." It truly has everything and the kitchen sink. You can read your mail, browse the Web, etc. in Emacs. It even has a built-in psychiatrist. Some regard this as an advantage, others feel it is bloated. Ultimately, you decide.

Disadvantages of vi and Emacs:
To the advanced user there are essentially none. For the Linux newbie who knows only Windows these editors can be a bit too intimidating (as the quote says: complicated, cryptic, unforgiving and dangerous). The biggest hurdle to overcome is the collection of sometimes strange and arbitrary editor commands that need to be learned.


[edit] Browsers

[edit] Image:firefox48.png Firefox

Firefox is the most popular open source web browser. It has great standards compliance, is fast and has all the features that can be expected of a modern browser, like tabs, popup and ad blocking and RSS integration. Moreover, it is cross-platform and works on Linux, Windows and Mac. Firefox also has a large collection of plugins available for it. Perhaps the only disadvantage of Firefox is that it doesn't integrate as well into desktop environments like KDE and GNOME as these environments' own browsers.

[edit] Image:konqueror64.png Konqueror

Konqueror is KDE's browser and file manager (sort of like Windows Explorer). It has good standards compliance and performance, and features such as tabs, ad and popup blocking and RSS integration. Konqueror's power lies in its excellent integration with the rest of KDE. It can view text and source files in an embedded editor and PDF files in an embedded PDF viewer. The file manager part also allows you to manipulate files over FTP, SSH, etc. Apple uses Konqueror's rendering engine in their Safari browser.

[edit] Image:opera48.png Opera

Opera is renowned for being the fastest browser on earth and it sure does live up to its reputation. Its standards compliance is great, it supports tabbed browsing, ad and popup blocking, RSS, and has a built-in bittorrent client. Other great features include page zooming and image blocking at the click of a button. Opera is free, but not open source.

[edit] Links & Lynx

Links and Lynx are two text-mode browsers – in other words, they are completely text-based. They are mentioned here simply to let you know that such things exist, and one can quite successfully browse most sites with them. Links can operate in a special "framebuffer" mode which allows it to display images and use the mouse.


[edit] Desktop Environments and Window Managers

[edit] Image:KDE64.png KDE

KDE is one of the desktop environments mentioned earlier. It includes pretty much all of the applications and utilities needed for daily use. For most people coming from Windows, KDE will be an easy transition and I would strongly recommend it to the Linux newbie. KDE is a very flexible and powerful desktop environment with a good level of integration between applications, most of which are highly configurable. It provides an easy to use environment for the inexperienced Linux user without sacrificing any of the power and flexibility that is valued by power users. KDE is fully network-enabled, meaning that all KDE applications can work with files over a variety of protocols such as FTP, SSH, NFS or SMB. This allows you, for example, to edit files directly on an FTP server without having to make changes locally and upload it yourself.

[edit] Image:gnome64.png GNOME

GNOME is another established desktop environment with very much the same functionality as KDE, but with a different look & feel and usage. In some ways it is more OS X-like and less Windows-like. GNOME provides the same collection of applications as KDE, such as a terminal, editor, file manager, calculator, etc. GNOME focuses more on simplicity than on configurability. Some people find it easier to use than KDE, but it lacks the flexibility appreciated by others. GNOME and KDE are more or less equally popular on Linux desktops.

[edit] IceWM

IceWM is not a complete desktop environment but a window manager. It provides a desktop and taskbar with a launch menu from which you can launch KDE, GNOME and other applications. It's a great window manager for the minimalist: Lightning fast with a lean and mean interface without needless bells and whistles. It lacks a decent menu and configuration system, but these exist as add-on modules.


[edit] Terminals

[edit] Konsole

Konsole is KDE's terminal. It is undoubtedly the most powerful terminal for Linux with functionality such as tabs, colour schemes, configurable scrollback history, searching, profiles and sessions. For those who appreciate eye-candy, it also supports transparency. It's very fast (as long as you use a fixed width font such as Lucida Typewriter or Fixed). Try out the tabs in Konsole – once you get used to it you may soon find it as indispensable as tabs in your favourite browser.

[edit] ATerm

ATerm is a fast, lightweight terminal. It doesn't have as many features as Konsole, but it's perfect for the minimalist. You'll have to read the man page to change the configuration options. The following command will launch ATerm with some nice options:

aterm -fg white -bg black -sr -sl 1000 -tr -sh 35 -geometry 90x28

You can right-click on the K Menu in KDE and choose "Menu Editor" to add an entry for ATerm using this command, if there isn't one already.

[edit] xterm

xterm is X's original terminal. Like ATerm, it is small and fast, and you'll need to read the man page if you want to configure it. xterm is the default terminal in IceWM.


[edit] Image:core64.png When Things Go Wrong (+)

One of Linux's strengths is it's ability to recover from problems, failures and crashes. There's a saying that goes: "Linux – because rebooting is for adding new hardware." It is not uncommon for Linux machines to run for weeks, months, sometimes even more than a year without the need for a reboot. One of the things that make this possible is the extensive control Linux gives you over your programs' processes. This section describes some of the ways you can avoid having to reboot when things go wrong.

[edit] Killing Misbehaving Processes

[edit] ps and kill

When you find that a program has hung or is generally misbehaving, you can use the ps and kill commands to terminate it (see the Process Management section). Say for example I have ssh'ed to kanagawa and for some reason the ssh session has stopped responding. First I will use ps to determine the ssh process's ID (or PID), and then use kill to terminate it:

# ps -aux
USER       PID %CPU %MEM   VSZ  RSS TTY      STAT START   TIME COMMAND
...
derick   14993  0.0  0.4  3164 1604 pts2     S    20:46   0:00 ssh kanagawa
...

# kill 14993

If a process does not die after killing it, you can try to use kill -9 (e.g.: kill -9 14993). However, as mentioned before, kill -9 should be used sparingly. It doesn't allow a process to terminate gracefully and clean up after itself.

One can also use the killall command to kill all processes with a given name. With killall, it is not necessary to first find the PID with ps if you know what the misbehaving process's name is. For example, if your program called prac3 has gone into an infinite loop, you can do:

killall prac3

[edit] top

The top program is also a very useful tool for finding misbehaving processes and terminating them. top displays a continually updated list of processes, which are by default sorted by CPU usage. When a process gets out of hand and starts eating up all of the CPU power, it will be displayed at the top of the listing. You can kill the process by pressing k, entering its process ID and pressing enter again (which sends the default TERM signal (15) to the process). Once again, if the process stubbornly refuses to die, follow the same procedure but enter 9 at the signal prompt to send the KILL signal.

[edit] KDE System Guard

Lastly, your graphical alternative to these programs is something like KDE's System Guard. To launch KDE System Guard, press Ctrl+Esc or run it from a terminal with ksysguard. You may have to click on the "User%" heading to sort processes by CPU usage.

Tip: There is a quick way to kill graphical applications. Pressing Alt+Ctrl+Esc will change the cursor into the infamous and deadly "Skull and Crossbones ™", with which you can kill anything just by clicking on it. Two warnings are in order, however: Firstly, killing with The Skull may sometimes kill a program's window but not necessarily its process. It's a good idea to use ps to make sure the process also terminated. Secondly, hand-eye coordination is important because misclicks are fatal. The Skull asks no questions.

[edit] Processes That Won't Die

Sometimes you may come across processes that seem immune even against kill -9. These processes are usually in an "uninterruptable I/O wait" state, indicated by a 'D' in ps's STAT column. This means that they are busy waiting for a read or write operation to a disk to complete, which cannot be interrupted. If you've tried to terminate such a process and it just won't go away, you'll have to wait for the Linux kernel to take care of it when it comes out of its uninterruptible state. Something else to note is that the kernel contains an "Out of Memory Killer" (called oomkill) that will promptly terminate any process that causes the system to run out of memory. Such a runaway process will first cause a lot of swap memory to be used (you can see the swap usage in top), which will slow down the system for a while, but eventually the Linux kernel will kill it and the system will return to normal.


[edit] Recovering From a Total Lock-Up of the GUI

In the rare and unfortunate case that everything stops responding and you cannot even reach a terminal to see what's going on, there is still hope. The Linux GUI is separated from the kernel and from other non-graphical programs, so they can be terminated separately when misbehaving. In the event that KDE or the underlying X Window System stops responding, you can switch out of graphical mode to text mode and log in on one of the virtual consoles. Pressing Alt+Ctrl+F1 will take you to the first virtual console.

Once logged in on a virtual console you can do anything except run graphical applications. From here you can try terminating the offending program. To switch back to graphical mode, press Alt+Ctrl+F7. There are six virtual terminals you can log in on (simultaneously, if you need to), accessed with Alt+Ctrl+F1,F2,F3... and so on. If killing one process doesn't help, keep on killing processes until things go back to normal.

What to do when it doesn't work:

If you're running out of processes to kill and things are still locked up (or you don't know what to kill), or you can't even get to a virtual terminal with Alt+Ctrl+F1, then you'll need to resort to more drastic measures. You can terminate the X Window System by pressing Alt+Ctrl+Backspace. IMPORTANT: This will immediately kill ALL GUI programs and programs started from within the GUI, including KDE, and you will lose any unsaved work. When X is killed, it will be restarted and you'll be returned to the login screen.

NOTE: Use this method responsibly. Do NOT kill X when someone is logged in and has locked the workstation while going away for a while. Only when it is clear that a person has "abandoned" the workstation and there are no other workstations to use should you terminate his/her session like this. If you find anyone who has terminated your session, please report them to the techteam (or at least report the time at which you found them logged in so they can be identified and addressed).

[edit] Final Words

This guide was written by Derick Swanepoel (wiki page: derick).


I hope that you have found this guide helpful and that it will help to make your Linux experience a pleasant one. The Linux universe is vast and the learning curve steep if you're only used to Windows, but if you are willing to learn new things you will be greatly rewarded by its power and flexibility.


If you have any comments or suggestions for this guide, please let me know via email or find me on TLUG's IRC server in #tlug.


If you have Linux questions or problems, there is a Tuks Linux Users Group (TLUG) that can assist you. You can visit the TLUG forums, or subscribe to the TLUG mailing list by sending an e-mail to [tlug-request@cs.up.ac.za] with the following line as the body of the message:

subscribe

Visit TLUG's website at http://www.tlug.org.za/.


Have a nice day.

Personal tools