This page is provided as a convenient way to download. It should also be helpful for people on dial-up to have one big page to read. A list of the other “AllOfs” can be found at http://linuxbasics.org/course/book/allallofs.
Please take into considerations that once you save this page, it cannot keep up with the dynamics of the wiki. If you find something to be corrected or improved, you need to check or edit the actual current wiki-page.
The current version of this document can be found at http://linuxbasics.org/course/book/index.
This book is licensed and may be distributed under the terms of the GNU Free Documentation License. A copy of the license can be found at http://linuxbasics.org/course/book/allof_appendix
Usually, these snapshots are updated daily between 05:00 and 05:15 UTC
This snapshot was created: Sun Jul 20 06:08:07 CEST 2008
This chapter is about configuring your environment. Now that we now how to use an editor, we can change all kinds of files to make ourselves feel better at home. After completing this chapter, you will know more about:
As we mentioned before, it is easy enough to make a mess of the system. We can’t put enough stress on the importance of keeping the place tidy. When you learn this from the start, it will become a good habit that will save you time when programming on a Linux or UNIX system or when confronted with system management tasks. Here are some ways of making life easier on yourself:
bin directory for your program files and scripts.700 dirname command.Complaint to the prime minister 050302 rather than letter1.
On some systems, the quota system may force you to clean up from time to time, or the physical limits of your hard disk may force you to make more space without running any monitoring programs. This section discusses a number of ways, besides using the rm command, to reclaim disk space.
Run the quota -v command to see how much space is left.
Sometimes the content of a file doesn’t interest you, but you need the file name as a marker (for instance, you just need the timestamp of a file, a reminder that the file was there or should be there some time in the future). Redirecting the output of a null command is how this is done in the Bourne and Bash shells:
andy:~> cat wishlist > placeholder andy:~> ls -la placeholder -rw-rw-r-- 1 andy andy 200 Jun 12 13:34 placeholder andy:~> > placeholder andy:~> ls -la placeholder -rw-rw-r-- 1 andy andy 0 Jun 12 13:35 placeholder
The process of reducing an existing file to a file with the same name that is 0 bytes large is called “truncating.”
For creating a new empty file, the same effect is obtained with the touch command. On an existing file, touch will only update the timestamp. See the Info pages on touch for more details.
To “almost” empty a file, use the tail command. Suppose user andy’s wishlist becomes rather long because he always adds stuff at the end but never deletes the things he actually gets. Now he only wants to keep the last five items:
andy:~> tail -5 wishlist > newlist andy:~> cat newlist > wishlist andy:~> rm newlist
Some Linux programs insist on writing all sorts of output in a log file. Usually there are options to only log errors, or to log a minimal amount of information, for example setting the debugging level of the program. But even then, you might not care about the log file. Here are some ways to get rid of them or at least set some limits to their size:
/dev/null; if you’re lucky the program won’t complain. Don’t do this with the log files of programs that run at system boot or programs that run from cron (see Chapter 4). These programs might replace the symbolic link with a small file that starts growing again.
Regularly clean out your mailbox, make sub-folders and automatic redirects using procmail (see the Info pages) or the filters of your favorite mail reading application. If you have a trash folder, clean it out on a regular basis.
To redirect mail, use the .forward file in your home directory. The Linux mail service looks for this file whenever it has to deliver local mail. The content of the file defines what the mail system should do with your mail. It can contain a single line holding a fully qualified E-mail address. In that case the system will send all your mail to this address. For instance, when renting space for a website, you might want to forward the mail destined for the webmaster to your own account in order not to waste disk space. The webmaster’s .forward may look like this:
webmaster@www ~/> cat .forward mike@pandora.be
Using mail forwarding is also useful to prevent yourself from having to check several different mailboxes. You can make every address point to a central and easily accessible account.
You can ask your system administrator to define a forward for you in the local mail aliases file, like when an account is being closed but E-mail remains active for a while.
When several users need access to the same file or program, when the original file name is too long or too difficult to remember, use a symbolic link instead of a separate copy for each user or purpose.
Multiple symbolic links may have different names, e.g. a link may be called monfichier in one user’s directory, and mylink in another’s. Multiple links (different names) to the same file may also occur in the same directory. This is often done in the /lib directory: when issuing the command
ls -l /lib
you will see that this directory is plenty of links pointing to the same files. These are created so that programs searching for one name would not get stuck, so they are pointed to the correct/current name of the libraries they need.
The shell contains a built-in command to limit file sizes, ulimit, which can also be used to display limitations on system resources:
cindy:~> ulimit -a core file size (blocks) 0 data seg size (kbytes) unlimited file size (blocks) unlimited max locked memory (kbytes) unlimited max memory size (kbytes) unlimited open files 1024 pipe size (512 bytes) 8 stack size (kbytes) 8192 cpu time (seconds) unlimited max user processes 512 virtual memory (kbytes) unlimited
Cindy is not a developer and doesn’t care about core dumps, which contain debugging information on a program. If you do want core dumps, you can set their size using the ulimit command. Read the Info pages on bash for a detailed explanation.
Compressed files are useful because they take less space on your hard disk. Another advantage is that it takes less bandwidth to send a compressed file over your network. A lot of files, such as the man pages, are stored in a compressed format on your system. Yet unpacking these to get a little bit of information and then having to compress them again is rather time-consuming. You don’t want to unpack a man page, for instance, read about an option to a command and then compress the man page again. Most people will probably forget to clean up after they found the information they needed.
So we have tools that work on compressed files, by uncompressing them only in memory. The actual compressed file stays on your disk as it is. Most systems support zgrep, zcat, bzless and such to prevent unnecessary decompressing/compressing actions. See your system’s binary directory and the Info pages.
See Chapter 9 for more on the actual compressing of files and examples on making archives.
The Bash prompt can do much more than displaying such simple information as your user name, the name of your machine and some indication about the present working directory. We can add other information such as the current date and time, number of connected users etc.
Before we begin, however, we will save our current prompt in another environment variable:
[jerry@nowhere jerry]$ MYPROMPT=$PS1 [jerry@nowhere jerry]$ echo $MYPROMPT [\u@\h \W]\$ [jerry@nowhere jerry]$
When we change the prompt now, for example by issuing the command PS1=→, we can always get our original prompt back with the command PS1=$MYPROMPT. You will, of course, also get it back when you reconnect, as long as you just fiddle with the prompt on the command line and avoid putting it in a shell configuration file.
In order to understand these prompts and the escape sequences used, we refer to the Bash Info or man pages.
export PS1="[\t \j] "
export PS1="[\d][\u@\h \w] : "
export PS1="{\!} "
export PS1="\[\033[1;35m\]\u@\h\[\033[0m\] "
export PS1="\[\033[1;35m\]\u\[\033[0m\] \[\033[1;34m\]\w\[\033[0m\] "
export PS1="\[\033[1;44m\]$USER is in \w\[\033[0m\] "
export PS1="\[\033[4;34m\]\u@\h \w \[\033[0m\]"
export PS1="\[\033[7;34m\]\u@\h \w \[\033[0m\] "
export PS1="\[\033[3;35m\]\u@\h \w \[\033[0m\]\a"
PS1=“… ”
Variables are exported so the subsequently executed commands will also know about the environment. The prompt configuration line that you want is best put in your shell configuration file, ~/.bashrc.
If you want, prompts can execute shell scripts and behave different under different conditions. You can even have the prompt play a tune every time you issue a command, although this gets boring pretty soon. More information can be found in the Bash-Prompt HOWTO.
A shell script is, as we saw in the shell configuration examples, a text file containing shell commands. When such a file is used as the first non-option argument when invoking Bash, and neither the -c nor -s option is supplied, Bash reads and executes commands from the file, then exits. This mode of operation creates a non-interactive shell. When Bash runs a shell script, it sets the special parameter 0 to the name of the file, rather than the name of the shell, and the positional parameters (everything following the name of the script) are set to the remaining arguments, if any are given. If no additional arguments are supplied, the positional parameters are unset.
A shell script may be made executable by using the chmod command to turn on the execute bit. When Bash finds such a file while searching the PATH for a command, it spawns a sub-shell to execute it. In other words, executing
filename ARGUMENTS
is equivalent to executing
bash filename ARGUMENTS
if “filename” is an executable shell script. This sub-shell reinitializes itself, so that the effect is as if a new shell had been invoked to interpret the script, with the exception that the locations of commands remembered by the parent (see hash in the Info pages) are retained by the child.
Most versions of UNIX make this a part of the operating system’s command execution mechanism. If the first line of a script begins with the two characters “#!”, the remainder of the line specifies an interpreter for the program. Thus, you can specify bash, awk, perl or some other interpreter or shell and write the rest of the script file in that language.
The arguments to the interpreter consist of a single optional argument following the interpreter name on the first line of the script file, followed by the name of the script file, followed by the rest of the arguments. Bash will perform this action on operating systems that do not handle it themselves.
Bash scripts often begin with
#! /bin/bash
(assuming that Bash has been installed in /bin), since this ensures that Bash will be used to interpret the script, even if it is executed under another shell.
A very simple script consisting of only one command, that says hello to the user executing it:
[jerry@nowhere ~] cat hello.sh #!/bin/bash echo "Hello $USER"
The script actually consists of only one command, echo, which uses the value of ($) the USER environment variable to print a string customized to the user issuing the command.
Another one-liner, used for displaying connected users:
#!/bin/bash who | cut -d " " -f 1 | sort -u
Here is a script consisting of some more lines, that I use to make backup copies of all files in a directory. The script first uses a loop set up by ‘for i in *’. It selects the name of the first file and calls it $i. Then it sets the name of the copy for the file, and then it copies the file. For each file, a message is printed. When ‘done’ is reached, it will go back to the top of the loop until it has completed all the files:
tille:~> cat bin/makebackupfiles.sh #!/bin/bash # make copies of all files in a directory for i in * do ORIG=$i DEST=$i.old cp "$ORIG" "$DEST" echo "copied $i" done
Just entering a line like cp * *.old won’t work, as you will notice when trying this on a set of test files. An echo command was added in order to display some activity. echo’s are generally useful when a script won’t work: insert one after each doubted step and you will find the error in no time.
The /etc/rc.d/init.d directory contains loads of examples. Let’s look at this script that controls the fictive ICanSeeYou server:
#!/bin/sh
# description: ICanSeeYou allows you to see networked people
# process name: ICanSeeYou
# pidfile: /var/run/ICanSeeYou/ICanSeeYou.pid
# config: /etc/ICanSeeYou.cfg
# Source function library.
. /etc/rc.d/init.d/functions
# See how (with which arguments) we were called.
case "$1" in
start)
echo -n "Starting ICanSeeYou: "
daemon ICanSeeYou
echo
touch /var/lock/subsys/ICanSeeYou
;;
stop)
echo -n "Shutting down ICanSeeYou: "
killproc ICanSeeYou
echo
rm -f /var/lock/subsys/ICanSeeYou
rm -f /var/run/ICanSeeYou/ICanSeeYou.pid
;;
status)
status ICanSeeYou
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
esac
exit 0
First, with the . command (dot) a set of shell functions, used by almost all shell scripts in /etc/rc.d/init.d, is loaded. Then a case command is issued, which defines 4 different ways the script can execute. An example might be ICanSeeYou start. The decision of which case to apply is made by reading the (first) argument to the script, with the expression $1.
When no compliant input is given, the default case, marked with an asterisk, is applied, upon which the script gives an error message. The case list is ended with the esac statement. In the start case the server program is started as a daemon, and a process ID and lock are assigned. In the stop case, the server process is traced down and stopped, and the lock and the PID are removed. Options, such as the daemon option, and functions like killproc, are defined in the /etc/rc.d/init.d/functions file. This setup is specific to the distribution used in this example. The initscripts on your system might use other functions, defined in other files, or none at all.
Upon success, the script returns an exit code of zero to its parent.
This script is a fine example of using functions, which make the script easier to read and the work done faster. Note that they use sh instead of bash, to make them useful on a wider range of systems. On a Linux system, calling bash as sh results in the shell running in POSIX-compliant mode.
The bash man pages contain more information about combining commands, for- and while-loops and regular expressions, as well as examples. A comprehensible Bash course for system administrators and power users, with exercises, from Machtelt Garrels, the original author of this guide, is at Bash Guide for Beginners. Detailed description of Bash features and applications is in the reference guide Advanced Bash Scripting.
Prev: Your text environment: Environment variables
Home
Next: The graphical environment
We already mentioned a couple of environment variables, such as PATH and HOME. Until now, we only saw examples in which they serve a certain purpose to the shell. But there are many other Linux utilities that need information about you in order to do a good job.
What other information do programs need apart from paths and home directories?
A lot of programs want to know about the kind of terminal you are using; this information is stored in the TERM variable. In text mode, this will be the linux terminal emulation, in graphical mode you are likely to use xterm. Lots of programs want to know what your favorite editor is, in case they have to start an editor in a subprocess. The shell you are using is stored in the SHELL variable, the operating system type in OS and so on. A list of all variables currently defined for your session can be viewed entering the printenv command.
The environment variables are managed by the shell. As opposed to regular shell variables, environment variables are inherited by any program you start, including another shell. New processes are assigned a copy of these variables, which they can read, modify and pass on in turn to their own child processes.
There is nothing special about variable names, except that the common ones are in upper case characters by convention. You may come up with any name you want, although there are standard variables that are important enough to be the same on every Linux system, such as PATH and HOME.
An individual variable’s content is usually displayed using the echo command, as in these examples:
debby:~> echo $PATH /usr/bin:/usr/sbin:/bin:/sbin:/usr/X11R6/bin:/usr/local/bin debby:~> echo $MANPATH /usr/man:/usr/share/man/:/usr/local/man:/usr/X11R6/man
If you want to change the content of a variable in a way that is useful to other programs, you have to export the new value from your environment into the environment that runs these programs. A common example is exporting the PATH variable. You may declare it as follows, in order to be able to play with the flight simulator software that is in /opt/FlightGear/bin:
debby:~> PATH=$PATH:/opt/FlightGear/bin
This instructs the shell to not only search programs in the current path, $PATH, but also in the additional directory /opt/FlightGear/bin.
However, as long as the new value of the PATH variable is not known to the environment, things will still not work:
debby:~> runfgfs bash: runfgfs: command not found
Exporting variables is done using the shell built-in command export:
debby:~> export PATH debby:~> runfgfs --flight simulator starts--
In Bash, we normally do this in one elegant step:
export VARIABLE=value
The same technique is used for the MANPATH variable, that tells the man command where to look for compressed man pages. If new software is added to the system in new or unusual directories, the documentation for it will probably also be in an unusual directory. If you want to read the man pages for the new software, extend the MANPATH variable:
debby:~> export MANPATH=$MANPATH:/opt/FlightGear/man debby:~> echo $MANPATH /usr/man:/usr/share/man:/usr/local/man:/usr/X11R6/man:/opt/FlightGear/man
You can avoid retyping this command in every window you open by adding it to one of your shell setup files, see Section 7.2.2.
The following table gives an overview of the most common predefined variables:
Table 7-1. Common environment variables
| Variable name | Stored information |
|---|---|
DISPLAY |
used by the X Window system to identify the display server |
DOMAIN |
domain name |
EDITOR |
stores your favorite line editor |
HISTSIZE |
size of the shell history file in number of lines |
HOME |
path to your home directory |
HOSTNAME |
local host name |
INPUTRC |
location of definition file for input devices such as keyboard |
LANG |
preferred language |
LD_LIBRARY_PATH |
paths to search for libraries |
LOGNAME |
login name |
MAIL |
location of your incoming mail folder |
MANPATH |
paths to search for man pages |
OS |
string describing the operating system |
OSTYPE |
more information about version etc. |
PAGER |
used by programs like man which need to know what to do in case output is more than one terminal window. |
PATH |
search paths for commands |
PS1 |
primary prompt |
PS2 |
secondary prompt |
PWD |
present working directory |
SHELL |
current shell |
TERM |
terminal type |
UID |
user ID |
USER(NAME) |
user name |
VISUAL |
your favorite full-screen editor |
XENVIRONMENT |
location of your personal settings for X behavior |
XFILESEARCHPATH |
paths to search for graphical libraries |
A lot of variables are not only predefined but also preset, using configuration files. We discuss these in the next section.
When entering the ls -al command to get a long listing of all files, including the ones starting with a dot, in your home directory, you will see one or more files starting with a . and ending in rc. For the case of bash, this is .bashrc. This is the counterpart of the system-wide configuration file /etc/bashrc.
When logging into an interactive login shell, login will do the authentication, set the environment and start your shell. In the case of bash, the next step is reading the general profile from /etc, if that file exists. bash then looks for ~/.bash_profile, ~/.bash_login and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. If none exists, /etc/bashrc is applied.
When a login shell exits, bash reads and executes commands from the file ~/.bash_logout, if it exists.
This procedure is explained in detail in the login and bash man pages.
Let’s look at some of these config files. First /etc/profile is read, in which important variables such as PATH, USER and HOSTNAME are set:
debby:~> cat /etc/profile
# /etc/profile
# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc
# Path manipulation
if [ `id -u` = 0 ] && ! echo $PATH | /bin/grep -q "/sbin" ; then
PATH=/sbin:$PATH
fi
if [ `id -u` = 0 ] && ! echo $PATH | /bin/grep -q "/usr/sbin" ; then
PATH=/usr/sbin:$PATH
fi
if [ `id -u` = 0 ] && ! echo $PATH | /bin/grep -q "/usr/local/sbin"
then
PATH=/usr/local/sbin:$PATH
fi
if ! echo $PATH | /bin/grep -q "/usr/X11R6/bin" ; then
PATH="$PATH:/usr/X11R6/bin"
fi
These lines check the path to set: if root opens a shell (user ID 0), it is checked that /sbin, /usr/sbin and /usr/local/sbin are in the path. If not, they are added. It is checked for everyone that /usr/X11R6/bin is in the path.
# No core files by default ulimit -S -c 0 > /dev/null 2>&1
All trash goes to /dev/null if the user doesn’t change this setting.
USER=`id -un` LOGNAME=$USER MAIL="/var/spool/mail/$USER" HOSTNAME=`/bin/hostname` HISTSIZE=1000
Here general variables are assigned their proper values.
if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ]; then
INPUTRC=/etc/inputrc
fi
If the variable INPUTRC is not set, and there is no .inputrc in the user’s home directory, then the default input control file is loaded.
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC
All variables are exported, so that they are available to other programs requesting information about your environment.
for i in /etc/profile.d/*.sh ; do
if [ -r $i ]; then
. $i
fi
done
unset i
All readable shell scripts from the /etc/profile.d directory are read and executed. These do things like enabling color-ls, aliasing vi to vim, setting locales etc. The temporary variable i is unset to prevent it from disturbing shell behavior later on.
Then bash looks for a .bash_profile in the user’s home directory:
debby:~> cat .bash_profile ################################################################# # # # .bash_profile file # # # # Executed from the bash shell when you log in. # # # ################################################################# source ~/.bashrc source ~/.bash_login
This very straightforward file instructs your shell to first read ~/.bashrc and then ~/.bash_login. You will encounter the source built-in shell command regularly when working in a shell environment: it is used to apply configuration changes to the current environment.
The ~/.bash_login file defines default file protection by setting the umask value, see Section 3.4.2.2. The ~/.bashrc file is used to define a bunch of user-specific aliases and functions and personal environment variables. It first reads /etc/bashrc, which describes the default prompt (PS1) and the default umask value. After that, you can add your own settings. If no ~/.bashrc exists, /etc/bashrc is read by default.
Your /etc/bashrc file might look like this:
debby:~> cat /etc/bashrc # /etc/bashrc # System wide functions and aliases # Environment stuff goes in /etc/profile # by default, we want this to get set. # Even for non-interactive, non-login shells. if [ `id -gn` = `id -un` -a `id -u` -gt 99 ]; then umask 002 else umask 022 fi
These lines set the umask value. Then, depending on the type of shell, the prompt is set:
# are we an interactive shell?
if [ "$PS1" ]; then
if [ -x /usr/bin/tput ]; then
if [ "x`tput kbs`" != "x" ]; then
# We can't do this with "dumb" terminal
stty erase `tput kbs`
elif [ -x /usr/bin/wc ]; then
if [ "`tput kbs|wc -c `" -gt 0 ]; then
# We can't do this with "dumb" terminal
stty erase `tput kbs`
fi
fi
fi
case $TERM in
xterm*)
if [ -e /etc/sysconfig/bash-prompt-xterm ]; then
PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm
else
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:\
${PWD/$HOME/~}\007"'
fi
;;
*)
[ -e /etc/sysconfig/bash-prompt-default ] && PROMPT_COMMAND=\
/etc/sysconfig/bash-prompt-default
;;
esac
[ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\h \W]\\$ "
if [ "x$SHLVL" != "x1" ]; then # We're not a login shell
for i in /etc/profile.d/*.sh; do
if [ -x $i ]; then
. $i
fi
done
fi
fi
Upon logout, the commands in ~/.bash_logout are executed, which can for instance clear the terminal, so that you have a clean window upon logging out of a remote session, or upon leaving the system console:
debby:~> cat .bash_logout # ~/.bash_logout clear
Let’s take a closer look at how these scripts work in the next section. Keep info bash close at hand.
Prev: General good housekeeping
Home
Next: The Bash prompt====== 7.3. The graphical environment ======
The average user may not care too much about his login settings, but Linux offers a wide variety of flashy window and desktop managers for use under X, the graphical environment. The use and configuration of window managers and desktops is straightforward and may even resemble the standard MS Windows, MacIntosh or UNIX CDE environment, although many Linux users prefer flashier desktops and fancier window managers. We won’t discuss the user specific configuration here. Just experiment and read the documentation using the built-in Help functions these managers provide and you will get along fine.
We will, however, take a closer look at the underlying system.
The X Window System is a network-transparent window system which runs on a wide range of computing and graphics machines. X Window System servers run on computers with bitmap displays. The X server distributes user input to and accepts output requests from several client programs through a variety of different interprocess communication channels. Although the most common case is for the client programs to be running on the same machine as the server, clients can be run transparently from other machines (including machines with different architectures and operating systems) as well. We will learn how to do this in Chapter 10 on networking and remote applications.
X supports overlapping hierarchical sub-windows and text and graphics operations, on both monochrome and color displays. The number of X client programs that use the X server is quite large. Some of the programs provided in the core X Consortium distribution include:
We refer again to the man pages of these commands for detailed information. More explanations on available functions can be found in the Xlib - C language X Interface manual that comes with your X distribution, the X Window System Protocol specification, and the various manuals and documentation of X toolkits. The /usr/share/doc directory contains references to these documents and many others.
Many other utilities, window managers, games, toolkits and gadgets are included as user-contributed software in the X Consortium distribution, or are available using anonymous FTP on the Internet. Good places to start are http://www.x.org and http://www.xfree.org.
Furthermore, all your graphical applications, such as your browser, your E-mail program, your image viewing programs, sound playing tools and so on, are all clients to your X server. Note that in normal operation, that is in graphical mode, X clients and the X server on Linux run on the same machine.
From the user’s perspective, every X server has a display name in the form of:
hostname:displaynumber.screennumber
This information is used by the application to determine how it should connect to the X server and which screen it should use by default (on displays with multiple monitors):
display is usually used to refer to a collection of monitors that share a common key board and pointer (mouse, tablet, etc.). Most workstations tend to only have one keyboard, and therefore, only one display. Larger, multi-user systems, however, frequently have several displays so that more than one person can be doing graphics work at once. To avoid confusion, each display on a machine is assigned a display number (beginning at 0) when the X server for that display is started. The display number must always be given in a display name.
On POSIX systems, the default display name is stored in your DISPLAY environment variable. This variable is set automatically by the xterm terminal emulator. However, when you log into another machine on a network, you might need to set DISPLAY by hand to point to your display, see Section 10.4.3.2.
More information can be found in the X man pages.
The layout of windows on the screen is controlled by special programs called window managers. Although many window managers will honor geometry specifications as given, others may choose to ignore them (requiring the user to explicitly draw the window’s region on the screen with the pointer, for example).
Since window managers are regular (albeit complex) client programs, a variety of different user interfaces can be built. The X Consortium distribution comes with a window manager named twm, but most users prefer something more fancy when system resources permit. Sawfish and Enlightenment are popular examples which allow each user to have a desktop according to mood and style.
A desktop manager makes use of one window manager or another for arranging your graphical desktop in a convenient way, with menubars, drop-down menus, informative messages, a clock, a program manager, a file manager and so on. Among the most popular desktop managers are Gnome and KDE, which both run on almost any Linux distribution and many other UNIX systems.
The X distribution that used to come with Linux, XFree86, uses the configuration file XF86Config for its initial setup. This file configures your video card and is searched for in a number of locations, although it is usually in /etc/X11.
If you see that the file /etc/X11/XF86Config is present on your system, a full description can be found in the Info or man pages about XF86Config.
Because of licensing issues with XFree86, newer systems usually come with the X.Org distribution of the X server and tools. The main configuration file here is xorg.conf, usually also in /etc/X11. The file consists of a number of sections that may occur in any order. The sections contain information about your monitor, your video adaptor, the screen configuration, your keyboard etcetera. As a user, you needn’t worry too much about what is in this file, since everything is normally determined at the time the system is installed.
Should you need to change graphical server settings, however, you can run the configuration tools or edit the configuration files that set up the infrastructure to use the X server. See the man pages for more information; your distribution might have its own tools. Since misconfiguration may result in unreadable garbage in graphical mode, you may want to make a backup copy of the configuration file before attempting to change it, just to be on the safe side.
Prev: Your text environment
Home
Next: Region specific settings
Setting the keyboard layout is done using the loadkeys command for text consoles. Use your local X configuration tool or edit the Keyboard section in XF86Config manually to configure the layout for graphical mode. The XkbdLayout is the one you want to set:
XkbLayout "us"
This is the default. Change it to your local settings by replacing the quoted value with any of the names listed in the subdirectories of your keymaps directory. If you can’t find the keymaps, try displaying their location on your system issuing the command
locate keymaps
It is possible to combine layout settings, like in this example:
Xkblayout "us,ru"
Make a backup of the /etc/X11/XF86Config file before editing it! You will need to use the root account to do this.
Log out and reconnect in order to reload X settings.
The Gnome Keyboard Applet enables real-time switching between layouts; no special pemissions are needed for using this program. KDE has a similar tool for switching between keyboard layouts.
Use the setfont tool to load fonts in text mode. Most systems come with a standard inputrc file which enables combining of characters, such as the French � (meta characters). The system admin should then add the line
export INPUTRC="/etc/inputrc"
to the /etc/bashrc file.
Setting time information is usually done at installation time. After that, it can be kept up to date using an NTP (Network Time Protocol) client. Most Linux systems run ntpd by default:
debby:~> ps -ef | grep ntpd ntp 24678 1 0 2002 ? 00:00:33 ntpd -U ntp
You can run ntpdate manually to set the time, on condition that you can reach a time server. The ntpd daemon should not be running when you adjust the time using ntpdate. Use a time server as argument to the command:
root@box:~# ntpdate 10.2.5.200 26 Oct 14:35:42 ntpdate[20364]: adjust time server 10.2.5.200 offset -0.008049 sec
See your system manual and the documentation that comes with the NTP package. Most desktop managers include tools to set the system time, providing that you have access to the system administrator’s account.
For setting the time zone correct, you can use tzconfig or timezone commands. Timezone information is usually set during the installation of your machine. Many systems have distribution-specific tools to configure it, see your system documentation.
If you’d rather get your messages from the system in Dutch or French, you may want to set the LANG and LANGUAGE environment variables, thus enabling locale support for the desired language and eventually the fonts related to character conventions in that language.
With most graphical login systems, such as gdm or kdm, you have the possibility to configure these language settings before logging in.
Note that on most systems, the default tends to be en_US.UTF-8 these days. This is not a problem, because systems where this is the default, will also come with all the programs supporting this encoding. Thus, vi can edit all the files on your system, cat won’t behave strange and so on.
Trouble starts when you connect to an older system not supporting this font encoding, or when you open a UTF-8 encoded file on a system supporting only 1-byte character fonts. The recode utility might come in handy to convert files from one character set to another. Read the man pages for an overview of features and usage. Another solution might be to temporarily work with another encoding definition, by setting the LANG environment variable:
debby:~> acroread /var/tmp/51434s.pdf Warning: charset "UTF-8" not supported, using "ISO8859-1". Aborted debby:~> set | grep UTF LANG=en_US.UTF-8 debby:~> export LANG=en_US debby:~> acroread /var/tmp/51434s.pdf <--new window opens-->
Refer to the Mozilla web site for guidance on how to get Firefox in your language. The OpenOffice.org web site has information on localization of your OpenOffice.org suite.
The list of HOWTOs contains references to Bangla, Belarusian, Chinese, Esperanto, Finnish, Francophone, Hebrew, Hellenic, Latvian, Polish, Portugese, Serbian, Slovak, Slovenian, Spanish, Thai and Turkish localization instructions.
Prev: The graphical environment
Home
Next: Installing new software
Most people are surprised to see that they have a running, usable computer after installing Linux; most distributions contain ample support for video and network cards, monitors and other external devices, so there is usually no need to install extra drivers. Also common tools such as office suites, web browsers, E-mail clients and such are included in the main distributions. Even so, an initial installation might not meet your requirements.
If you just can’t find what you need, maybe it is not installed on your system. It may also be that you have the required software, but it does not do what it is supposed to do. Remember that Linux moves fast, and software improves on a daily basis. Don’t waste your time troubleshooting problems that might already be resolved.
You can update your system or add packages to it at any time you want. Most software comes in packages. Extra software may be found on your installation CDs or on the Internet. The website of your Linux distribution is a good place to start looking for additional software and contains instructions about how to install it on your type of Linux, see Appendix A. Always read the documentation that comes with new software, and any installation guidelines the package might contain. All software comes with a README file, which you are very strongly advised to read.
The following sections give an overview of package managers. There is much more to this subject, even regular updates of source packages is manageable automatically; we only list the most commonly known systems. Always refer to the documentation for your specific distribution for advised procedures.
RPM, the RedHat Package Manager, is a powerful package manager that you can use to install, update and remove packages. It allows you to search for packages and keeps track of the files that come with each package. A system is built-in so that you can verify the authenticity of packages downloaded from the Internet. Advanced users can build their own packages with RPM.
An RPM package consists of an archive of files and meta-data used to install and erase the archive files. The meta-data includes helper scripts, file attributes, and descriptive information about the package. Packages come in two varieties: binary packages, used to encapsulate software to be installed, and source packages, containing the source code and recipe necessary to produce binary packages.
Many distributions support RPM packages, among the popular ones RedHat Enterprise Linux, Mandriva (former Mandrake), Fedora Core and SuSE Linux. Apart from the advice for your distribution, you will want to read man rpm.
Most packages are simply installed with the upgrade option, -U, whether the package is already installed or not. The RPM package contains a complete version of the program, which overwrites existing versions or installs as a new package. The typical usage is as follows:
rpm -Uvh /path/to/rpm-package(s)
The -v option generates more verbose output, and -h makes rpm print a progress bar:
[root@jupiter tmp]# rpm -Uvh totem-0.99.5-1.fr.i386.rpm Preparing... ########################################### [100%] 1:totem ########################################### [100%] [root@jupiter tmp]#
New kernel packages, however, are installed with the install option -i, which does not overwrite existing version(s) of the package. That way, you will still be able to boot your system with the old kernel if the new one does not work.
You can also use rpm to check whether a package is installed on your system:
[david@jupiter ~] rpm -qa | grep vim vim-minimal-6.1-29 vim-X11-6.1-29 vim-enhanced-6.1-29 vim-common-6.1-29
Or you can find out which package contains a certain file or executable:
[david@jupiter ~] rpm -qf /etc/profile setup-2.5.25-1 [david@jupiter ~] which cat cat is /bin/cat [david@jupiter ~] rpm -qf /bin/cat coreutils-4.5.3-19
Note that you need not have access to administrative privileges in order to use rpm to query the RPM database. You only need to be root when adding, modifying or deleting packages.
Below is one last example, demonstrating how to uninstall a package using rpm:
[root@jupiter root]# rpm -e totem [root@jupiter root]#
Note that uninstalling is not that verbose by default, it is normal that you don’t see much happening. When in doubt, use rpm -qa again to verify that the package has been removed.
RPM can do much more than the couple of basic functions we discussed in this introduction; the RPM HOWTO contains further references.
Update Agent, which originally only supported RedHat RPM packages, is now ported to a wider set of software, including non-RedHat repositories. This tool provides a complete system for updating the RPM packages on a RedHat or Fedora Core system. On the command line, type up2date to update your system. On the desktop, by default a small icon is activated, telling you whether or not there are updates available for your system.
Yellowdog’s Updater Modified (yum) is another tool that recently became more popular. It is an interactive but automated update program for installing, updating or removing RPM packages on a system. It is the tool of choice on Fedora systems.
On SuSE Linux, everything is done with YaST, Yet another Setup Tool, which supports a wide variety of system administration tasks, among which updating RPM packages. Starting from SuSE Linux 7.1 you can also upgrade using a web interface and YOU, Yast Online Update.
Mandrake Linux and Mandriva provide so-called URPMI tools, a set of wrapper programs that make installing new software easier for the user. These tools combine with RPMDrake and MandrakeUpdate to provide everything needed for smooth install and uninstall of software packages. MandrakeOnline offers an extended range of services and can automatically notify administrators when updates are available for your particular Mandrake system. See man urpmi, among others, for more info.
Also the KDE and Gnome desktop suites have their own (graphical) versions of package managers.
This package format is the default on Debian GNU/Linux and its derivatives. The Debian package format is becoming more and more popular. At the time of this writing, 5 of the top 10 distributions use it.
There are many package managers tools for .deb packages, some who have existed for a longer time than others, with various strengths and purposes. In ‘historical order’, there is dselect, dpkg, the APT tools like apt-get and aptitude, and finally synaptic, a GUI tool. KDE also has a package manager, Kpackage, which manages both .rpm and .deb packages.
Checking whether a package is installed is done using the dpkg command. For instance, if you want to know which version of the Gallery software is installed on your machine:
nghtwsh@gorefest:~$ dpkg -l *gallery* Desired=Unknown/Install/Remove/Purge/Hold | Status=Not/Installed/Config-files/Unpacked/Failed-config/Half-installed |/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad) ||/ Name Version Description +++-==============-==============-============================================ ii gallery 1.5-1sarge2 a web-based photo album written in php
The “ii” prefix means the package is installed. Should you see “un” as a prefix, that means that the package is known in the list that your computer keeps, but that it is not installed.
Searching which package a file belongs to is done using the -S to dpkg:
nghtwsh@gorefest:~$ dpkg -S /bin/cat coreutils: /bin/cat
More information can be found in the Info pages for dpkg.
Discovery of orphaned dependancy packages can also be found by using the deborphan command.
Debian’s APT (Advanced Package Tool) system is arguably the most effective Linux package system available. Most of the power of APT comes from the vast repository system. Almost any program you can possibly want is easy to install using one of the tools below.
apt-get is a widely-used package manager, even on non-DEB systems.
A powerful command line tool for handling .deb Debian packages is apt-get, which comes with an excellent man page describing how to install and update packages and how to upgrade single packages or your entire distribution. APT has its roots in the Debian GNU/Linux distribution, where it is the default manager for the Debian packages. APT has been ported to work with RPM packages as well. The main advantage of APT is that it is free and flexible to use. It will allow you to set up systems similar to the distribution specific (and in some cases commercial) ones listed in other sections. It also allows you to remove parts of meta-packages (packages consisting of many other packages), without removing the whole thing, or packages you wish to keep.
Generally, when first using apt-get, you will need to get an index of the available packages. This is done using the command
apt-get update
After that, you can use apt-get to upgrade your system:
apt-get upgrade
Do this often, it’s an easy way to keep your system up-to-date and thus safe.
Apart from this general usage, apt-get is also very fast for installing individual packages. This is how it works:
[david@jupiter ~] su - -c "apt-get install xsnow" Password: Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: libwww-ssl0 Use 'apt-get autoremove' to remove them. The following NEW packages will be installed: xsnow 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. Need to get 32.1kB of archives. After unpacking 168kB of additional disk space will be used. Get:1 http://archive.ubuntu.com edgy/multiverse xsnow 1:1.42-6ubuntu1 [32.1kB] Fetched 32.1kB in 0s (40.4kB/s) Selecting previously deselected package xsnow. (Reading database ... 148915 files and directories currently installed.) Unpacking xsnow (from .../xsnow_1%3a1.42-6ubuntu1_i386.deb) ... Setting up xsnow (1.42-6ubuntu1) ...
Note the -c option to the su command, which indicates to the root shell to only execute this command, and then return to the user’s environment. This way, you cannot forget to quit the root account.
If there are any dependencies on other packages, apt-get will download and install these supporting packages.
Note also the suggested apt-get autoremove to remove the package which is no longer required. This was a dependency needed for a package that has been removed previously.
More information can be found in the APT HOWTO.
dselect is also a standard tool for managing .deb packages. It is used to select packages that you want to find, to install, upgrade, or to just scroll to see what is available. It will also run during the installation of a Debian system and help you to define the access method to use, to list available packages and to configure packages.
One drawback of dselect is its complicated tree with obscure commands in the ncurses text interface. It can be very daunting to both new and advanced Debian users. That might be why it is not the most used package manager at this point. However, as in all software, its most salient commands or features keep it from falling in disuse. Expect to run at times into dselect commands if you deal with Debian or Debian-based distribution.
The Debian web site contains all information you need, including a “dselect Documentation for Beginners”.
aptitude is a very powerful command line tool for handling .deb Debian packages. It shares, with apt-get, the favors of a large contingent of Debian users. aptitude, like dselect, uses an ncurses text interface, but is much easier and more intuitive to use.
Among the strong points of aptitude, handling dependency problems, it keeps track of what packages are installed due to dependencies alone, and removes those packages when they are no longer needed.
You can also go to the top of the “Installed Packages” branch, and tell it to uninstall all installed packages. It will politely refuse to easily remove essential packages (by forcing you to type “Yes, I realize that this is a very bad idea” in order to proceed), but will clean your system of everything else. This is a good way to go back to the beginning without re-installing. While aptitude is a very powerful APT frontend, it is still quite daunting for a new user to use.
However, one feature to be wary of is its tendency to remove far more packages than you asked for. You can’t pick and choose as easily as with other packages managers. Sometimes it’s an asset and sometimes it’s a liability.
A word of caution: use of both aptitude and apt-get does not always make for an easy marriage. If you choose one manager over another between these two, try to stick with it as much as possible.
synaptic attempts to meet the software installation needs of the new user. synaptic was originally released by a Debian derivative called Storm Linux which went under in 2001. It has an easy to use GTK interface and has very sensible defaults. Ubuntu, being heavily desktop-oriented, naturally centered their package management around synaptic.
One of the stronger points of synaptic is the search feature. It is easy to search and find a package, or information about it, even when you don’t know its exact name. One of the drawback of synaptic is that it is a GUI manager, and at times, this proves to be a problem. In those cases, fire up apt-get or aptitude.
The largest part of Linux programs is Free/Open Source, so source packages are available for these programs. Source files are needed for compiling your own program version. Sources for a program can be downloaded from its web site, often as a compressed tarball (program-version.tar.gz or similar).
Specific requirements, dependencies and installation instructions are provided in the README file. You will probably need a C compiler, gcc. This GNU C compiler is included in most Linux systems and is ported to many other platforms.
Some distributions package managers use compressed tarballs to install packages and manage dependencies. Gentoo emerge is one example.
For RPM-based distributions, the source is often provided in the program-version.src.rpm.
Debian, and most distributions based on it, provide the adapted source which can be obtained using apt-get source.
The first thing you do after installing a new system is apply updates; this applies to all operating systems and Linux is not different.
The updates for most Linux systems can usually be found on a nearby site mirroring your distribution. Lists of sites offering this service can be found at your distribution’s web site, see Appendix A.
Updates should be applied regularly, daily if possible–but every couple of weeks would be a reasonable start. You really should try to have the most recent version of your distribution, since Linux changes constantly. As we said before, new features, improvements and bug fixes are supplied at a steady rhythm, and sometimes important security problems are addressed.
The good news is that most Linux distributions provide tools so that you don’t have to upgrade tens of packages daily by hand. Consult the documentation of the respective package manager tool for best results.
Most Linux installations are fine if you periodically upgrade your distribution. The upgrade procedure will install a new kernel when needed and make all necessary changes to your system. You should only compile or install a new kernel manually if you need kernel features that are not supported by the default kernel included in your Linux distribution.
Whether compiling your own optimized kernel or using a pre-compiled kernel package, install it in co-existence with the old kernel until you are sure that everything works according to plan.
Then create a dual boot system that will allow you to choose which kernel to boot by updating your boot loader configuration file grub.conf. This is a simple example:
## default num
# This sets which boots by default. Numbering starts from 0, and
# the entry number 0 is the default if the command is not used.
default=0
## timeout sec
# Set a timeout, in seconds, before automatically booting the default entry.
timeout=10
splashimage=(hd0,0)/grub/splash.xpm.gz
## New kernel. Note that there is a separate boot partition at (hd0,0) or /dev/hda1.
# The root of the system is at /dev/hda8.
# If the boot directory were also on /dev/hda8, it would have:
# root (hd0,7)
# kernel /boot/vmlinuz-2.4.9-31 ro root=/dev/hda8
# initrd /boot/initrd-2.4.9-31.img
title Red Hat Linux new (2.4.9-31)
root (hd0,0)
kernel /vmlinuz-2.4.9-31 ro root=/dev/hda8
initrd /initrd-2.4.9-31.img
## Old kernel stanza left in in case new kernel fails
title old-kernel
root (hd0,0)
kernel /vmlinuz-2.4.9-21 ro root=/dev/hda8
initrd /initrd-2.4.9-21.img
After the new kernel has proven to work, you may remove the lines for the old one from the GRUB config file, although it is best to wait a couple of days just to be sure.
This is basically done in the same way as installing packages manually, except that you have to append the file system of the CD to your machine’s file system to make it accessible. On most systems, this will be done automatically upon insertion of a CD in the drive because the automount daemon is started up at boot time. If your CD is not made available automatically, issue the mount command in a terminal window. Depending on your actual system configuration, a line similar to this one will usually do the trick:
mount /dev/cdrom /mnt/cdrom
On some systems, only root can mount removable media; this depends on the configuration.
For automation purposes, the CD drive usually has an entry in /etc/fstab, which lists the file systems and their mount points, that make up your file system tree. This is such a line:
[david@jupiter ~] grep cdrom /etc/fstab /dev/cdrom /mnt/cdrom iso9660 noauto,owner,ro 0 0
This indicates that the system will understand the command mount /mnt/cdrom. The noauto option means that on this system, CDs are not mounted at boot time.
You may even try to right click on the CD icon on your desktop to mount the CD if your file manager doesn’t do it for you. You can check whether it worked issuing the mount command with no arguments:
[david@jupiter ~] mount | grep cdrom /dev/cdrom on /mnt/cdrom type iso9660 (ro,nosuid,nodev)
After mounting the CD, you can change directories, usually to the mount point /mnt/cdrom, where you can access the content of the CD-ROM. Use the same commands for dealing with files and directories as you would use for files on the hard disk.
In order to get the CD out of the drive after you’ve finished using it, the file system on the CD should be unused. Even being in one of the subdirectories of the mount point, /mnt/cdrom in our example, will be considered as “using the file system”, so you should get out of there. Do this for instance by typing cd with no arguments, which will put you back in your home directory. After that, you can either use the command
umount /mnt/cdrom
or
eject cdrom
Prev: Region specific settings
Home
Next: Summary ====== 7.6. Summary ======
When everything has its place, that means already half the work is done.
While keeping order is important, it is equally important to feel at home in your environment, whether text or graphical. The text environment is controlled through the shell setup files. The graphical environment is primarily dependent on the X server configuration, on which a number of other applications are built, such as window and desktop managers and graphical applications, each with their own config files. You should read the system and program specific documentation to find out about how to configure them.
Regional settings such as keyboard setup, installing appropriate fonts and language support are best done at installation time.
Software is managed either automatically or manually using a package system.
hello, world. Give it appropriate permissions so it can be run. Test your script.music to keep audio files, a directory documents for your notes, and so on. And use them!-la.testfile > testfile not work?
Copyright (c) by the authors.
This section of the wiki is licensed under the terms of the GNU Free Documentation License.
See the LBook-licensing page for details.
Linux® is a registered trademark of Linus Torvalds.