Chapter 4. Running Linux

Table of Contents

Introduction
System Architecture
User Accounts
Processes
Files and File Structure
Permissions
Using the Command Line
Navigating
Listing Content
Basic File Manipulation
Editing Text Files
Linking Files and Directories
File / Command Completion
Switching Terminals
Logging Out
Shutting Down
Getting Help
Man Pages
Info Pages
Immediate Syntax Help
Package-provided Documentation
Online Documentation
Exercises
Further Resources

Introduction

In order to work with Linux you need access to a Linux environment. The best environment is an installed Linux distribution on your system, but you can use other environments such as Linux Live CDs (bootable CDs with a ready-to-run operating system on it). Installing Linux is very distribution-specific and Gentoo's installation procedure is well documented on the Gentoo site. I will not discuss the installation procedure yet. Later in this book, I will focus on the command-line Gentoo installation because then you'll have a much better view on the various installation steps. Right now, I'm going to talk about a few Linux-specific topics which are quite important to understand, but without going in too much detail: almost every topic will be discussed in great length later.

Users who are not used to working with Linux or Unix will find that it is quite different from other operating systems (notably: Microsoft Windows). In System Architecture I give a quick overview of the main differences. Further down, I elaborate on using the command line interface of Linux (which is definitely a must-know if you are going to work with Gentoo Linux). Finally, I cover how to find help on the commands.

System Architecture

Linux is a multi-user platform. The administrator user is called the root user and can do anything on the system. Although it is perfectly possible to work on your system as this administrator, it is advised to create individual accounts for everyone who needs access to the system and only grant those users access to important resources or administrative commands (there are tools that allow a user to switch from one user to another or run certain commands as a different user).

For your personal PC, this probably means you're going to create a single additional account for yourself. If the PC is shared with many people (say household PC or a work station at your office) you most likely want to create accounts for every possible person. Sharing an account isn't good practice: if you need to share files and directories with other people, there are better ways than sharing the same account.

The personal account you use is limited, yet definitely not unusable. A few of the differences between a non-privileged account and the root account are:

  • the personal account can only modify files it has created itself, so there is no possibility of corrupting your system (as the operating system files are immutable for the personal accounts). This also means that the personal account cannot install any additional software on the system (that's okay - I will tell you how to elevate your privileges later on so that you can manage your system when you need to).

  • the personal account cannot fill up a partition to the point that the system is endangered. On several file sysems, 5% of each partition is reserved for privileged users only. Although this is not applicable to all file systems (btrfs comes to mind) such a restriction does come in handy to guarantee the availability of the system.

  • if malicious events happen using your personal account, traces of what has happened might show up in log files that the personal account cannot tamper with

  • ...

Every task a user starts results in a process on the system. For instance, a user that fires up a browser results in at least one process representing the browser program. By default, this process runs with the privileges of this user and has therefore only access to the files and resources of this user. Another reason why not to use the root account: you don't want a malicious script that gets executed in your browser, and which triggers an exploitable bug (this isn't fantasy, it might happen) cause your browser to start wiping out important system files...

Files and directories themselves are, permission-wise, represented with three sets of permissions: one for the owner, one for the owning group and one for everyone. More on the file privileges later.

User Accounts

As the root user is an administrator account with no privilege limitations whatsoever, any action ran by the root user can potentially hurt your system:

  • removing the wrong files or directories (there is no undelete option)

  • removing or manipulating system files (possibly resulting in a malfunctioning system - and a reboot won't solve this)

  • disabling networking or changing network behaviour

  • placing files on wrong places (possibly losing files or interfering with system operations)

  • killing or otherwise manipulating the wrong process(es) (possibly resulting in service malfunction, shutdown or misbehaviour)

  • ...

For this reason, user accounts should be created. A default user account:

  • can only edit or remove files that belong to this user

  • can not interfere with system-wide settings (including networking, device access, ...)

  • can only place files inside his own (dedicated) home directory

  • can only kill / manipulate processes that he has launched himself

Important

It is still possible for non-root user accounts to do harm. For instance, a malfunctioning program executed by a user might still remove all user files from the file system. Although this is a major disaster for end users (please, do not forget to take backups regularly) the system itself can still run as the operating system files are not touched.

Next to user accounts, any Linux installation has system accounts as well. These are regular accounts just like the user accounts (with the same limitations), but cannot be used to log on (they do not have a valid password), often have no dedicated home directory and are used by the operating system to run specific services with limited rights (increasing security) rather than administrative rights.

To ease managing user accounts (and permissions / access to resources), users are made part of groups. Access to files can be managed through group ownership whereas every member of this group can access (or even write to) the file. A user can be part of many groups.

Processes

A process is a running task on the system. Each process runs as a particular user: this not only means that that process can only access resources that are available for that user, but also that only this user (and the root user) can manipulate the process (for instance, kill the process).

Each process has one parent (except the top process, which is always the init process) and can have one or more child processes. If a process dies, all its children die as well (so never try to kill the init process as it would result in a total annihilation of all processes on the system).

Running processes do not necessarily consume CPU cycles. An idle system can easily be running a few dozen (or even up to a hundred) processes. This is because processes have various states: actively running, sleeping, waiting, stopped, ... Luckily, the Linux Operating System is very efficient in balancing the requirements of the applications with the available resources so you, as an end user, do not notice that this many processes are running.

Note

One process can also have multiple threads. Threads are part of an application (but managed by the operating system) and allow running code within an application in parallel. A program with several threads is still a single process.

Files and File Structure

On Linux (and all the Unix and Unix-like operating systems) the file system is hierarchically structured. At the top, you have the file system root, which is named "/". Below you'll have files and directories, following the standard described in a previous section, the section called “File system Hierarchy Standard”. Every position within the structure has its meaning. An example is /home/swift, which is the home directory of the "swift" user account. Another example is /usr/share/doc/googleearth-4.2.198.2451/, the location where a specific version of the Google Earth program stores its package documentation.

Next to regular files (like text files or program-related files) and directories, Linux also has the notion of:

  • links, which are other names for the same file (allowing for one file to have multiple references),

  • symbolic links, which are pointers to other files (differs from links because it is merely a pointer, so it can point to something that doesn't exist) and are somewhat (but not quite) comparable to Microsoft Windows' shortcuts.

  • named pipes or FIFOs, which are temporary buffers where one process can write to and another process can read from

  • unix domain sockets, which are created by one process and where several other processes can write to or receive information from

  • character and block device file, which represents a hardware device on the system, allowing to exchange data with the device through regular file operations

All these special files are represented as files on the Linux file system. Take /dev/sda1 as an example. It represents the first partition (1) on the first (a) SCSI device (sd) known by the system. /dev/sda1 is a block device file because read/write operations occur in blocks (certain amount of data) whereas character device operations are on a character-by-character basis.

I will be discussing device files, and how Linux manages them, in a later chapter.

Permissions

Files (and directories and any of the special files talked about previously - I am going to refer to those as "files" as well throughout this book) are associated with three sets of permissions: one for the owner, one for the group owner and one for all the rest. Each set contains several flags:

  • read access to the file or directory

  • write access to the file or directory

  • execute rights on the file (probably because it is an application binary or a script) or entering rights on the directory (meaning you can jump inside the directory)

Next to these three sets, additional permissions can be set for executable files and directories, but these are far less important to understand at this moment:

  • set user/group id on the file (when the file is executed, the process is not ran as the user/group who executed it but as the owner) or directory (only applies to the group set; in this case, files created inside the directory automatically get the group ownership of the directory, allowing to easily share files between accounts)

  • restriction deletion flag (restricts deletion of files inside the affected directory unless the user is the owner of the file or directory)

The restriction deletion flag needs some explanation. It is used on world-writable directories (a well-known example is /tmp, where temporary files can be stored) and used to prevent users to remove files they didn't create. A world-writable directory would otherwise allow other users to remove files from that directory (as they too have write access to the directory). The restriction deletion flag is also known as the sticky flag.

Using the Command Line

Most Linux distributions, once booted up, provide you with a graphical logon screen, or even log you on automatically. With Gentoo Linux, this isn't the case. Rather, you'll be greeted with a command-line prompt asking you to identify yourself:

This is seaheaven.homeworld (Linux x86_64 3.8.5) 22:30:00

seaheaven login: 

At this prompt, you are asked to enter your user name which you have undoubtedly created during the Linux installation. Next, you are asked for your account password. If the user name exists and the password matches, then you are greeted with a command line prompt. The next listing shows a typical prompt for the account with user name "captain" on a system with host name "seaheaven":

captain@seaheaven ~ $

The prompt is structured as follows:

  1. the user name of the account logged on to the system

  2. the host name of the system where the user is logged on to

  3. the current location where the user is on the file system (~ means the users' home directory)

  4. a prompt sign telling the user if he is a regular user ($) or root user (#).

In the following sections, I'll give you a quick introduction to the world of the Linux command line.

Navigating

The prompt is actually something rendered by a shell. A shell is an interactive program which takes on commands from the user input (keyboard) and executes those on the system. One prime example of commands are those used for navigating through the file system:

  • pwd shows the present working directory (where the user is currently in)

  • cd allows a user to change the directory he is in

  • ls shows the contents of the current directory (listing) or any other location if asked

An example session is shown below.

captain@seaheaven ~ $ pwd
/home/captain
captain@seaheaven ~ $ ls
Documents     Movies       Music       Pictures
TODO
captain@seaheaven ~ $ cd Documents
captain@seaheaven Documents $ pwd
/home/captain/Documents

To navigate from one directory to another, there are a couple of ways to use the cd command. Note that the pwd command is shown to show the current location. It is not part of the process of navigating between directories!

  • You can use a relative path to go down a tree. In the example, the "cd Documents" goes from /home/captain to /home/captain/Documents through the relative path "Documents".

    $ pwd
    /home/captain
    $ cd Documents
    $ pwd
    /home/captain/Documents
  • You can go up through the special name '..' (dot dot), so "cd .." would go from /home/captain/Documents to /home/captain.

    $ pwd
    /home/captain/Documents
    $ cd ..
    $ pwd
    /home/captain
  • You can also use absolute paths. For instance, to go immediately to /etc/init.d (a special directory we'll talk about later) you would type "cd /etc/init.d".

    $ pwd
    /home/captain/Documents
    $ cd /etc/init.d
    $ pwd
    /etc/init.d
  • A special character is the ~ (tilde) which means the home directory, so "cd ~" would go to your home directory. Even shorter, just entering "cd" would go to your home directory. The ~ can be used in two ways: either to denote your home directory (cd ~/Documents goes to /home/captain/Documents) or someone else's home directory. In the latter case, you append the user name to the ~ sign, so: "cd ~raghat/public_html/" translates to /home/raghat/public_html.

    $ pwd
    /etc/init.d
    $ cd ~/Documents
    $ pwd
    /home/captain/Documents

If for some reason the change directory command cannot succeed (no permission to enter the directory, or the directory doesn't exist) you will be notified of the failure.

$ pwd
/home/captain
$ cd /etc/cron.daily
bash: cd: /etc/cron.daily: Permission denied
$ pwd
/home/captain

Listing Content

To list the contents of a directory, you would use the ls command. By default, it shows the files and directories of the current directory, but ls is one of those commands that takes a multitude of options. It is not my intention to describe each and every single option, but there are a few which are quite important to know right now.

First of all, the "-l" option shows not only the files and directories of a certain directory (or the current directory) but also information about each file / directory:

captain@seaheaven ~ $ ls -l
drwxr-xr-x 2 captain users 4096 2013-10-31 22:24 Documents
drwxr-xr-x 2 captain users 4096 2013-10-31 22:24 Movies
drwxr-xr-x 2 captain users 4096 2013-10-31 22:25 Music
drwxr-xr-x 2 captain users 4096 2013-10-31 22:24 Pictures
-rw-r--r-- 1 captain users   66 2013-10-31 22:30 TODO

The information contains, amongst other things, the permission sets (three times three characters: Read, Write and eXecute), the owning user and group, the size (directories are in multiples of 4 kilobytes in this case) and their creation date.

Another interesting option is "-a", which lets the ls command show all files (including the hidden files). A hidden file on a Unix / Linux system starts with a dot. Inside your home directory you'll find a variety of hidden files by default, the example below shows just a subset of such files.

captain@seaheaven ~ $ ls -a
.            Documents    Movies    Music     Pictures
..           .history     .maildir  .profile  .vimrc

Hidden files are not meant to really hide the files, but rather not to show them using regular listings so they do not clutter the listing output too much. Most hidden files are configuration files (like the .vimrc file which is the configuration file for the vim editor for the current user).

As with most command line utilities, you can combine arguments; you are even able to put them together, so ls -l -a is the same as ls -la. The order also doesn't matter, so ls -la and ls -al are both the same.

Analyzing ls -l output

You will find that you often use "ls -l" to get the necessary information about a file or directory. As such I give you a quick overview of the meaning of the various fields in ls' output:

$ ls -l 12-servicemanagement.xml
-rw-r--r-- 1 swift users 26976 Apr 22 21:21 12-servicemanagement.xml
|<+><+><+> | <-+-> <-+-> <-+-> <-----+----> <---------+------------->
| |  |  |  |   |     |     |         |                `- file name or directory name
| |  |  |  |   |     |     |         `- last modification time
| |  |  |  |   |     |     `- size (in bytes)
| |  |  |  |   |     `- group owning the file or directory
| |  |  |  |   `- user owning the file or directory
| |  |  |  `- number of hard links to the file or directory
| |  |  `- privileges (in this case: read-only) for everybody
| |  `- privileges (in this case: read-only) for owning group ("users")
| `- privileges (in this case: read-write) for owning user ("swift")
`- type of file (in this case: regular file)

Basic File Manipulation

The most basic manipulations are copying, moving, renaming and deleting files, which we explain below...

Copying Files & Directories

To copy a file you would use the cp command. Its basic syntax is simple: cp source destination. The destination can be a directory in which case the file is copied to that directory. If the destination is a file name, the file is copied to that file(name).

captain@seaheaven ~ $ ls Documents
captain@seaheaven ~ $ cp TODO Documents/tasks.txt
captain@seaheaven ~ $ ls Documents
tasks.txt
captain@seaheaven ~ $ cp TODO Documents
captain@seaheaven ~ $ ls Documents
TODO      tasks.txt

By default, the cp command creates the destination file with the privileges and ownership of the user that is executing the command. In the next example, I copy the file /etc/inittab to the current directory (.):

$ ls -l /etc/inittab
-rw-r--r-- 1 root root 1890 Feb 15 20:39 /etc/inittab
$ cp /etc/inittab .
$ ls -l inittab
-rw-r--r-- 1 swift users 1890 Apr 22 22:49 inittab

You can ask cp to preserve all information (like access privileges, ownership and time stamps) although you might need to be root to do so.

To recursively copy an entire directory and its content, use the -r option. For instance, the following example would copy the folder workdocuments and all files and directories inside it to the current working directory.

$ cp -r /media/usb/workdocuments .

Moving and Renaming Files & Directories

To move a file, the mv command should be used. Its syntax is mv source destination. If the destination is a file name rather than a directory, then the mv command also performs the task of renaming files. In the next example, the tasks.txt file is moved from the Documents folder to the /media/usb/workdocuments directory:

captain@seaheaven ~ $ ls Documents/
TODO     tasks.txt
captain@seaheaven ~ $ mv Documents/tasks.txt /media/usb/workdocuments
captain@seaheaven ~ $ ls Documents/
TODO
captain@seaheaven ~ $ ls /media/usb/workdocuments
tasks.txt

Removing Files & Directories

The final task is removing files. The rm command uses the following syntax: rm filename. To remove an entire directory, you could just give the directory name, but that only works if the directory is empty. Otherwise, you need to add the "-r" option (which stands for recursive: the directory and every file and directory inside it).

captain@seaheaven ~ $ rm Documents/TODO
captain@seaheaven ~ $ rm tasks.txt

A popular set of options to rm is "-rf": it tells rm to remove all files and directories recursively, and also tells it not to ask the user for validation (force). Make sure you know what you are doing, Linux does not have an undo feature!

$ rm -rf Documents

Luckily, rm only works with the privileges of the user that is executing it, so you cannot accidentally remove system files if you aren't running as the privileged root user:

$ rm -f /etc/passwd
rm: cannot remove '/etc/passwd': Permission denied

Editing Text Files

An important task for any Linux user is knowing how to edit text files. There are many text editors around, such as the popular vim and emacs. Gentoo recommends nano as your first editor because it is easy to work with and understand. My preference is for vim.

Using Nano

As such, a quick primer in the use of nano. If you launch nano it shows you the main editor screen for a new file. If you launch nano with a file name as its argument, it opens up the text file, ready for editing. As an example, I open up the TODO file using nano:

captain@seaheaven ~ $ nano TODO

Figure 4.1. nano editor opened with the TODO file as its working document

nano editor opened with the TODO file as its working document

The first line shows the name of the file opened while the last two lines show you a summary of the keyboard commands to manipulate the file. The ^ character means that you have to press the Control character (Ctrl), so to save the file you would press Ctrl+O. To exit the editor, press Ctrl+X.

Some text files are very sensitive to newlines - configuration files are the most important ones. By default, nano automatically wraps lines when you hit the sidebar. To inform nano that you want to keep lines as they are, add the "-w" argument: "nano -w TODO". This is the recommended approach when editing configuration files.

Viewing Text Files

If you want to view the content of a text file but don't want to launch the text editor, you can use cat or less. This also allows you to view the content of files without accidentally modifying them.

  • With cat, you "dump" the content of a file to the terminal. If the file is large, all text will scroll by very quickly. You can try to scroll up using Shift+PgUp but this buffer is limited in length.

  • With less, you view the content of a file page by page. The less command is called a pager and supports scrolling up / down (with the arrow keys or using the PgUp/PgDown keys), searching for specific text, ...

The less pager is not only used for viewing content of text files, but also for manual pages (which are discussed further down this chapter).

Table 4.1. Short summary of frequently used actions for the less pager

scroll down one linee, j, <return> or arrow key down
scroll up one liney, k or arrow key up
scroll down one pagef, <space> or PgDown
scroll up one pageb or PgUp
/<searchtext>search forward for <searchtext>, use "n" for every next hit
?<searchtext>search backward for <searchtext>, use "?" for every previous hit
hdisplay the help screen

In case you were wondering, the name less is a hint to an older, still supported pager called more. With more, you can also view the content of a file page by page, but more only supports scrolling down one line (<return>) or page (<space>). So less is more... than more.

Linking Files and Directories

Linux supports two types of links: symbolic links and hard links. You might wonder why I'm already telling you here in the introductionary chapter on running Linux. Well, that's because symbolic links are often used in Linux, whereas you'll find output related to hard links all over the place. In fact, we already had some output related to hard links earlier: in the output of the "ls -l" command.

Symbolic links, also known as symlinks, are the easiest to understand. They're not real files, but rather references to files somewhere on the file system. Their reference is a location string, which allows the link to be used across media and even to files that don't exist (any more). As an example, you could have a symbolic link that points to /home/swift/TODO, even when this file doesn't exist (any more).

Hard links, on the contrary, are immediate links. They actually refer to the same location on the disk as their target file (through inode's) and the file system will not release this location as free space until there are no references to this location. In fact, every file you see in the file system is a link to a location. With hard links, you just create additional links.

Due to their technology, hard links can only point to file locations on the same medium and they cannot handle directories.

To create links, use ln (hard links) or ln -s (symlinks):

$ ln targetfilename newfilename
$ ln -s targetfilename newfilename

Thanks to links, you can manage your files more easily. For instance, you can have an important text file located inside ~/Documents/Work/Thesis/myThesis.txt but link to it from your home directory (~/myThesis.txt points to ~/Documents/Work/Thesis/myThesis.txt) so that you don't have to traverse all these directories every time you want to open/edit the file.

File / Command Completion

A powerful feature of most Linux shells is file and command completion.

When you want to edit a file called, for instance, TODO, you can start with typing "nano T" followed by the <tab> key. If TODO is the only file or directory that starts with an T, the shell will automatically expand the command to "nano TODO". If there are more files or directories that start with T, typing <tab> twice will show you a list of candidates.

The same is true for commands. If nano is the only command starting with na (it isn't, but suppose it is) then typing "na" followed by a <tab> expands the command to nano. Pressing <tab> twice if it isn't the only command displays all matches:

$ na<tab><tab>
namei           nautilus
nano            nasl
nasm            native2ascii
$ na

Switching Terminals

One of Unix / Linux' advantages is the support for multiple terminals. When you are logged on to your system, you are actually watching one of the (virtual) terminals, most likely the first one. You can switch from one terminal to another using Alt+F# where F# is F1, F2, ... If you are on a graphical session, you'll need to use Ctrl+Alt+F# first. The graphical screen is positioned at the first terminal that can not be used to log on to (most likely Alt+F7).

The support for multiple terminals allows you to log on to your system several times and spread the tasks you want to execute in parallel across the various terminals. For instance, if you are configuring a program, you might want to have the configuration file itself open in one terminal and the program in another.

Hint: if you are working on the command line, you can also use the chvt command to switch between terminals: chvt 2 switches to the second terminal (similar to Alt+F2).

Logging Out

To log out from an existing session, enter exit or press Ctrl+d:

captain@seaheaven ~ $ exit

This is seaheaven.homeworld (Linux x86_64 3.8.5) 22:30:00

seaheaven login: 

Shutting Down

Finally, if you want to shut down your system, you will first need to become root. You can do this by switching to another terminal and log on as root, but you can also use the su command. This command will ask you to enter the root password after which you are known to the system as the root user:

captain@seaheaven ~ $ su -
Password: (Enter root password)
root@seaheaven ~ # 

Now, you can issue the shutdown command to shut down (-h) or reboot (-r) the system immediately:

root@seaheaven ~ # shutdown -h now

Getting Help

Linux might seem a bit complex at first, especially because the tools novice users use are the same tools that experts use, making the tools accept expert options starters wouldn't understand. Handbooks such as this one can only help users find their way, but once in a while any user, beginner or advanced, will need something to fall back to. Luckily, there are several resources you can address...

Man Pages

The manual page is available on the Linux system itself and can be accessed through the man command. By entering man followed by the command you want information about you receive the manual page of that command, explaining what the command does, what syntax you should use, what options it supports and what commands or files are related to this command.

~$ man emerge

The manual page is usually structured as follows:

  • name of the command with a one-line description

  • synopsis of the command, showing the syntax the command accepts

  • options of the command with an explanation of each option

  • further information on the command, like usage restrictions, default behaviour, ...

  • copyright and authorship information

  • related manual pages

Manual pages not only exist for commands, but for files (configuration files or device files), system calls and library functions (programming related information) and even standards and conventions. These topics are categorized in the following sections with the accompanying numbers:

  1. user commands

  2. system calls

  3. library functions

  4. special files (device files)

  5. file formats and protocols

  6. games and funny programs

  7. overview, conventions and miscellaneous topics

  8. administrative and privileged commands

For information about these sections, open up the introduction page for each section. For instance, the introduction page for the games section can be accessed through man 6 intro. Knowing what sections are available can be important, especially when there are topics in different sections which have the same name. An example is passwd: there is a manual page for the passwd command (man 1 passwd) and one for the passwd file (man 5 passwd). If one would enter man passwd, the first section that has a manual page for the topic is displayed (in this case, the first section).

Once you are inside a manual page, you can navigate through it using the up/down arrow keys and the PgUp/PgDn keys. You can also search for some terms (press / followed by the term) and more. A full explanation of all the commands of the manual viewer (which, on most systems, is the less tool) can be obtained by pressing 'h'.

To quit viewing the manual page, press 'q'.

If you know that a manual page exists somewhere, but you do not know its name, you can use the apropos command (which is the equivalent of man -k). Giving a keyword, the command will give a list of manual pages that are related to the keyword given. To build the database, you might need to run makewhatis first. On most systems, this is already scheduled to happen in the background on a daily basis.

~$ apropos ebuild

Info Pages

Another reference tool on your system is the info page help system. The info tool allows you to browse through info pages using a hierarchical approach (next/previous section, go upwards, ...) as well as using hyperlinks (select a topic in the info page to go to the section on that topic).

Let's take a look at the GCC info pages:

~$ info gcc
...
File: gcc.info,  Node: Top,  Next: G++ and GCC,  Up: (DIR)

Introduction
************

This manual documents how to use the GNU compilers, as well as their
features and incompatibilities, and how to report bugs.  It corresponds
to GCC version 4.1.2.  The internals of the GNU compilers, including
how to port them to new targets and some information about how to write
...

At the top of the info page you find where you are in the sequence of documents (as this is the first page, there is no real previous section nor upwards section). The next topic (which you can go to by pressing n) is "G++ and GCC".

Inside the text you will find text snippets following by two colons:

* G++ and GCC::     You can compile C or C++ programs.
* Standards::       Language standards supported by GCC.
* Invoking GCC::    Command options supported by `gcc'.
* C Implementation:: How GCC implements the ISO C specification.
* C Extensions::    GNU extensions to the C language family.
* C++ Extensions::  GNU extensions to the C++ language.
* Objective-C::     GNU Objective-C runtime features.

These texts are links which allow you to jump to that topic. Go with the cursor to "Invoking GCC" and press return:

File: gcc.info,  Node: Invoking GCC,  Next: C Implementation,  Prev: Standards,    Up: Top

3 GCC Command Options
*********************

When you invoke GCC, it normally does preprocessing, compilation,
assembly and linking.  The "overall options" allow you to stop this
process at an intermediate stage.  For example, the `-c' option says
not to run the linker.  Then the output consists of object files output
by the assembler.

You are now in the node called "Invoking GCC". The next (n) section is "C Implementation", the previous (p) is "Standards" and if you go up (u), you get to the top of the info document again.

Info pages are well used by various GNU projects (such as GCC). However, manual pages are more popular - perhaps because most developers find them easier to write.

Immediate Syntax Help

If you are not looking for an explanation on the command but want to know its syntax, most commands provide immediate help through the -h or --help arguments:

$ man -h
man, version 1.6e

usage: man [-adfhktwW] [section] [-M path] [-P pager] [-S list]
           [-m system] [-p string] name ...

  a : find all matching entries
  c : do not use cat file
  d : print gobs of debugging information
  D : as for -d, but also display the pages
  f : same as whatis(1)
  h : print this help message
  k : same as apropos(1)
  K : search for a string in all pages
  t : use troff to format pages for printing
  w : print location of man page(s) that would be displayed
      (if no name given: print directories that would be searched)
  W : as for -w, but display filenames only

  C file   : use `file' as configuration file
  M path   : set search path for manual pages to `path'
  P pager  : use program `pager' to display pages
  S list   : colon separated section list
  m system : search for alternate system's man pages
  p string : string tells which preprocessors to run
               e - [n]eqn(1)   p - pic(1)    t - tbl(1)
               g - grap(1)     r - refer(1)  v - vgrind(1)

Package-provided Documentation

Some packages provide more documentation in the form of guides (in HTML, PDF or other formats), README files and more. You will find most of this documentation at /usr/share/doc. Gentoo Linux compresses the documents using bzip2 or gzip (both well known compression tools in the Unix world). To view the documents, you will first need to decompress those into a location you have write privileges to.

For instance, the zip package contains a document explaining what algorithm the tool uses to (de)compress data:

$ cd /usr/share/doc/zip-*
$ ls
algorith.txt.bz2   BUGS.bz2            CHANGES.bz2      MANUAL.bz2
README.bz2         timezone.txt.bz2    txtvsbin.txt.bz2 WHATSNEW.bz2
WHERE.bz2           ziplimit.txt.bz2
$ bunzip2 -c algoritm.txt.bz2 > ~/algorithm.txt

The resulting file, algorithm.txt, can be found in the home directory (~ is an abbreviation for the home directory of the current user). In this case, the file is a regular text file which can be viewed through the less command, which is the same command used for manual pages.

In the above example, a redirection is used: the output of one command (bunzip2 -c algorithm.txt.bz2) is not shown on the screen, but rather redirected into a file (algorithm.txt). Redirection is discussed later on.

It is also possible to immediately read the (compressed) file using the bzless command:

$ bzless algorithm.txt.bz2

Online Documentation

Most projects have extensive documentation available. You are certainly advised to take a look at the projects' web sites or search through the internet for available guides and books. Sometimes, the best documentation is not written by the project itself but by satisfied users.

Exercises

  1. Try to organize your home directory in logical sections. For instance, create directories where you put your personal documents, pictures, work-related documents and temporary documents.

  2. Unix/Linux systems generally offer four compression methods. Whereas Zip is well known on the Microsoft Windows operating system, Unix/Linux uses GZip or BZip2 together with tar. How is "tar" used with gzip/bzip2? What is the fourth compression method?

  3. As stated, Unix/Linux systems have no undo functionality: when you remove a file, it is removed. However, due to the technicalities of removing files (in essence only the reference to the file is removed, but its content remains on disk until it is overwritten) there are tools available that help you recover files. Try finding a few examples of such file recovery utilities for Linux.

Further Resources