Chapter 7. Home sweet /home. Linux Linux
โฆษณา
โฆษณา
Chapter 7. Home sweet /home
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:
♦ Organizing your environment
♦ Common shell setup files
♦ Shell configuration
♦
Configuring the prompt
♦ Configuring the graphical environment
♦ Sound and video applications
♦ Display and window managers
♦ How the X client−server system works
♦
Language and font settings
♦ Installing new software
♦ Updating existing packages
7.1. General good housekeeping
7.1.1. Introduction
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:
• Make a bin
directory for your program files and scripts.
• Organize non−executable files in appropriate directories, and make as many directories as you like.
Examples include separate directories for images, documents, projects, downloaded files, spreadsheets, personal files, and so on.
• Make directories private with the chmod
700 dirname
command.
• Give your files sensible names, such as
Complaint to the prime minister 050302 rather than letter1
.
7.1.2. Make space
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.
Chapter 7. Home sweet /home 110
Introduction to Linux
7.1.2.1. Emptying files
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
7.1.2.2. More about log files
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:
• Try removing the log file when the program is not running, if you are sure that you won't need it again. Some programs may even see, when restarted, that there is no log file and will therefore not log.
•
If you remove the log file and the program recreates it, read the documentation for this particular program in search for command options that avoid making log files.
• Try making smaller log files by logging only the information that is relevant to you, or by logging only significant information.
• Try replacing the log file with a symbolic link to
/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
growing again.
Chapter 7. Home sweet /home 111
Introduction to Linux
7.1.2.3. Mail
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
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.
7.1.2.4. Save space with a link
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.
7.1.2.5. Limit file sizes
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
Chapter 7. Home sweet /home 112
Introduction to Linux
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.
7.1.2.6. Compressed files
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.
7.2. Your text environment
7.2.1. Environment variables
7.2.1.1. General
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
.
Chapter 7. Home sweet /home 113
Introduction to Linux
7.2.1.2. Exporting variables
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,
7.2.1.3. Reserved variables
The following table gives an overview of the most common predefined variables:
Table 7−1. Common environment variables
Chapter 7. Home sweet /home 114
Introduction to Linux
Variable name
DISPLAY
Stored information
used by the X Window system to identify the display server
DOMAIN
EDITOR
HISTSIZE
HOME
LOGNAME
MAIL domain name stores your favorite line editor size of the shell history file in number of lines path to your home directory
HOSTNAME
INPUTRC local host name location of definition file for input devices such as keyboard
LANG preferred language
LD_LIBRARY_PATH paths to search for libraries login name location of your incoming mail folder
MANPATH
OS
OSTYPE
PAGER
PATH
PS1
PS2
PWD
SHELL
TERM
UID paths to search for man pages string describing the operating system more information about version etc.
used by programs like man which need to know what to do in case output is more than one terminal window.
search paths for commands primary prompt secondary prompt present working directory current shell terminal type user ID user name
USER(NAME)
VISUAL
XENVIRONMENT your favorite full−screen editor 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.
7.2.2. Shell setup files
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.
Chapter 7. Home sweet /home 115
Introduction to Linux
This procedure is explained in detail in the login and bash man pages.
7.2.3. A typical set of setup files
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.
Chapter 7. Home sweet /home 116
Introduction to Linux 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 straight forward 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: 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
# 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
Chapter 7. Home sweet /home 117
Introduction to Linux
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.
7.2.4. The Bash prompt
7.2.4.1. Introduction
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.
Chapter 7. Home sweet /home 118
Introduction to Linux
7.2.4.2. Some examples
In order to understand these prompts and the escape sequences used, we refer to the Bash Info or man pages.
•
export PS1 =
"[\t \j] "
Displays time of day and number of running jobs
•
export
PS1
=
"[\d][\u@\h \w] : "
Displays date, user name, host name and current working directory. Note that \W displays only base names of the present working directory.
•
export
PS1
=
"{\!} "
Displays history number for each command.
•
export PS1 =
"\[\033[1;35m\]\u@\h\[\033[0m\] "
Displays user@host in pink.
•
export
PS1
=
"\[\033[1;35m\]\u\[\033[0m\] \[\033[1;34m\]\w\[\033[0m\] "
Sets the user name in pink and the present working directory in blue.
•
export
PS1
=
"\[\033[1;44m\]$USER is in \w\[\033[0m\] "
Prompt for people who have difficulties seeing the difference between the prompt and what they type.
•
export
PS1
=
"\[\033[4;34m\]\u@\h \w \[\033[0m\]"
Underlined prompt.
•
export
PS1
=
"\[\033[7;34m\]\u@\h \w \[\033[0m\] "
White characters on a blue background.
•
export PS1 =
"\[\033[3;35m\]\u@\h \w \[\033[0m\]\a"
Pink prompt in a lighter font that alerts you when your commands have finished.
•
export
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 way it gets boring pretty soon.
More information can be found in the Bash−Prompt HOWTO.
7.2.5. Shell scripts
7.2.5.1. What are scripts?
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 are set to the remaining arguments, if any are
Chapter 7. Home sweet /home 119
Introduction to Linux 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.
7.2.5.2. Some simple examples
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 makes a list of all the files in the current directory and puts it in the variable
LIST
. Then it sets the name of the copy for each file, and then it copies the file. For each file, a message is printed: tille:~>
cat bin/makebackupfiles.sh
#!/bin/bash
# make copies of all files in a directory
LIST=`ls` for i in $LIST; do
ORIG=$i
Chapter 7. Home sweet /home 120
Introduction to Linux
DEST=$i.old
cp $ORIG $DEST
echo "copied $i" done
The cut command is used in this example to separate the actual file name from the file name suffix. Just entering a line like mv
*.wav *.mp3
won't work. 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 asteriks, 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
Chapter 7. Home sweet /home 121
Introduction to Linux 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 the same author as this Introduction to Linux guide, is at http://tille.xalasys.com/training/bash/. Detailed description of Bash features and applications is in the reference guide Advanced Bash Scripting.
7.3. The graphical environment
7.3.1. Introduction
The average user may not care too much about his login settings, but Linux offers a wide variety of flashing 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.
7.3.2. The X Window 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
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:
•
xterm
: a terminal emulator
•
twm
: a minimalistic window manager
•
xdm
: a display manager
•
xconsole
: a console redirect program
•
bitmap
: a bitmap editor
Chapter 7. Home sweet /home 122
Introduction to Linux
•
xauth
, xhost and iceauth: access control programs
•
xset
, xmodmap and many others: user preference setting programs
•
xclock
: a clock
•
xlsfonts
and others: a font displayer, utilities for listing information about fonts, windows and displays
•
xfs
: a font server
• ...
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.
7.3.2.1. Display names
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):
• hostname: The host name specifies the name of the client machine to which the display is physically connected. If the host name is not given, the most efficient way of communicating to a server on the same machine will be used.
• displaynumber: The phrase "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.
•
screen number: Some displays share a single keyboard and pointer among two or more monitors.
Since each monitor has its own set of windows, each screen is assigned a screen number (beginning at
0) when the X server for that display is started. If the screen number is not given, screen 0 will be used.
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.3.3.
More information can be found in the X man pages.
Chapter 7. Home sweet /home 123
Introduction to Linux
7.3.2.2. Window and desktop managers
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.
KDE applications in Gnome/Gnome applications in KDE
You don't need to start your desktop in KDE in order to be able to run KDE applications. If you have the
KDE libraries installed (the kdelibs package), you can run these applications from the Gnome menus or start them from a Gnome terminal.
Running Gnome applications in a KDE environment is a bit more tricky, because there is no single set of base−libraries in Gnome. However, the dependencies and thus extra packages you might have to install will become clear when running or installing such an application.
7.3.3. X server configuration
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 XFree86 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.
Chapter 7. Home sweet /home 124
Introduction to Linux
7.4. Sound and video
7.4.1. Sound card configuration
Most Linux distributions provide tools that probe your system for sound cards. Most currently available plug−and−play sound cards should be recognized automatically. If you can hear the samples, just click OK and everything will be set up for you.
If your card is not detected automatically, you may be presented with a list of sound cards and/or of sound card properties from which to choose. After that, you will have to provide the correct I/O port, IRQ and DMA settings. Information about these settings can be found in your sound card documentation. If you are on a dual boot system with MS Windows, this information can be found in the Windows Control Panel as well.
7.4.2. If automatic sound card detection fails
If your soundcard is not supported by default, you will need to apply other techniques. These are described in the Linux Sound HOWTO.
7.4.3. Sound and video playing
7.4.3.1. CD playing and copying
The cdp package comes with most distributions and provides cdp or cdplay, a text−based CD player. Desktop managers usually include a graphical tool, such as the gnome−cd player in Gnome, that can be started from a menu.
Be sure to understand the difference between an audio CD and a data CD. You do not have to mount an audio
CD into the file system in order to listen to it. This is because the data on such a CD are not Linux file system data; they are accessed and sent to the audio output channel directly, using a CD player program. If your CD is a data CD containing
.mp3
files, you will first need to mount it into the file system, and then use one of the programs that we discuss below in order to play the music. How to mount CDs into the file system is
The cdparanoia tool from the package with the same name reads audio directly as data from the CD, without analog conversions, and writes data to a file or pipe in different formats, of which
.wav
is probably the most popular. Various tools for conversion to other formats, such as
.mp3
, come with most distributions or are downloadable as separate packages. The GNU project provides several CD playing, ripping and encoding tools, database managers; see the Free Software Directory, Audio section for detailed information.
Audio−CD creation is eased, among many others, with the kaudiocreator tool from the KDE suite. It comes with clear information from the KDE Help Center and is included on systems that have the kdemultimedia package installed.
CD burning is covered in general in Section 9.2.2.
Chapter 7. Home sweet /home 125
Introduction to Linux
7.4.3.2. Playing music files
7.4.3.2.1. mp3 files
The popular
.mp3
format is widely supported on Linux machines. Most distributions include multiple programs that can play these files. Among many other applications, XMMS, which is presented in the screenshot below, is one of the most wide−spread, partially because it has the same look and feel as the
Windows tool.
Figure 7−1. XMMS mp3 player
Also very popular for playing music are AmaroK, a KDE application that is steadily gaining popularity, and
MPlayer, which can also play movies.
Restrictions
Some distributions don't allow you to play MP3's without modifying your configuration, this is due to license restrictions on the MP3 tools. You might need to install extra software to be able to play your music.
7.4.3.2.2. Other formats
An (incomplete) overview of other common sound playing and manipulating software:
• Ogg Vorbis: Free audio format: see the GNU audio directory for tools − they might be included in your distribution as well.
• Real audio and video: realplay from RealNetworks.
• SoX or Sound eXchange: actually a sound converter, comes with the play program. Plays
.wav
,
.ogg
and various other formats, including raw binary formats.
• Playmidi: a MIDI player, see the GNU directory.
• AlsaPlayer: from the Advanced Linux Sound Architecture project, see the AlsaPlayer web site.
•
mplayer
: plays just about anything, including mp3 files. More info on the MPlayerHQ website.
•
hxplay
: supports RealAudio and RealVideo, mp3, mp4 audio, Flash, wav and more, see HelixDNA.
•
rhythmbox
: based on the GStremaer framework, can play everything supported in GStreamner, which claims to be able to play everything, see the RhythmBox and GStreamer sites.
Check your system documentation for particular tools.
I don't have these applications on my system!
A lot of the tools and applications discussed in the above sections are optional software. It is possible that such applications are not installed on your system by default, but that you can find them in your distribution as additional packages. It might also very well be that the application that you are looking
Chapter 7. Home sweet /home 126
Introduction to Linux for is not in your distribution at all. In that case, you need to download it from the application's web site.
7.4.3.3. Volume control aumix
and alsamixer are two common text tools for adjusting audio controls. The alsamixer has a graphical interface when started from the Gnome menu or as gnome−alsamixer from the command line. The kmix tool does the same in KDE.
Regardless of how you choose to listen to music or other sounds, remember that there may be other people who may not be interested in hearing you or your computer. Try to be courteous, especially in office environments. And use a quality head−set.
7.4.3.4. Video playing, streams and television watching
Various players are available:
•
xine
: a free video player
•
ogle
: DVD player
•
okle
: KDE version of ogle
•
mplayer
: Movie Player for Linux
•
gstreamer
: upcoming multimedia framework project developing the GStreamer library and accompanying tools for audio and video recording, editing and playing, to be included in Gnome. See http://www.gstreamer.net for more.
•
totem
: plays both audio and video files, audio CDs, VCD and DVD.
•
realplay
: from RealNetworks.
•
hxplay
: a Real alternative, see HelixDNA.
Most likely, you will find one of these in your graphical menus.
TLDP released a new document recently that is very appropriate for this section. It is entitled DVD Playback
HOWTO and describes the different tools available for viewing movies on a system that has a DVD drive. It is a fine addition to the DVD HOWTO that explains installation of the drive.
For watching TV there is choice of the following tools, among many others for watching and capturing TV, video and other streams:
•
tvtime
: great program with station management, interaction with teletext, film mode and much more.
•
zapping
: Gnome−specific TV viewer.
•
xawtv
: X11 TV viewer.
7.5. Region specific settings
7.5.1. Keyboard setup
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"
Chapter 7. Home sweet /home 127
Introduction to Linux
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.
7.5.2. Fonts
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.
7.5.3. Date and time zone
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
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.
7.5.4. Language
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.
Chapter 7. Home sweet /home 128
Introduction to Linux
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−−>
7.5.5. Specific information for Belgium
The Belgian HOWTO gives more detailed information on configuring your machine for Flanders, la Wallonie and the Oostkantons, on how to get on the Internet in Belgium and contains a list of Belgian providers of
Linux related commercial and free services.
The Francophones HOWTO discusses the available support for the French language in−depth.
7.5.6. Other countries
The list of HOWTOs contains references to Bangla, Belarusian, Chinese, Esperanto, Finnish, Hebrew,
Hellenic, Latvian, Polish, Portugese, Serbian, Slovak, Slovenian, Spanish, Thai and Turkish localization instructions.
7.6. Installing new software
7.6.1. General
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.
Chapter 7. Home sweet /home 129
Introduction to Linux
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.
7.6.2. Package formats
7.6.2.1. RPM packages
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 other 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, least to 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
Chapter 7. Home sweet /home 130
Introduction to Linux
[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.
7.6.2.2. DEB packages
This package format is the default on Debian GNU/Linux, where dselect is the standard tool for managing the packages. It is used to select packages that you want to install or upgrade, but 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.
The Debian web site contains all information you need, including a "dselect Documentation for Beginners".
7.6.2.3. Source packages
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). For RPM−based distributions, the source is often provided in the program−version.src.rpm
. Debian, and most distributions based on it, provide themselves the adapted source which can be obtained using apt−get
source
.
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.
7.6.3. Automating package management and updates
7.6.3.1. General remarks
The first thing you do after installing a new system is applying 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.
Chapter 7. Home sweet /home 131
Introduction to Linux
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. The following sections give an overview of "package manager 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.
7.6.3.2. APT
The Advanced Package Tool is a management system for software packages. The command line tool for handling packages is apt−get, which comes with an excellent man page describing how to install and update packages and how to upgrade singular 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 the next sections.
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... Done
The following NEW packages will be installed:
xsnow
0 packages upgraded, 1 newly installed, 0 removed and 3 not upgraded.
Need to get 33.6kB of archives.
After unpacking 104kB of additional disk space will be used.
Get:1 http://ayo.freshrpms.net redhat/9/i386/os xsnow 1.42−10 [33.6kB]
Fetched 33.6kB in 0s (106kB/s)
Executing RPM (−Uvh)...
Preparing... ########################################### [100%]
1:xsnow ########################################### [100%]
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.
Chapter 7. Home sweet /home 132
Introduction to Linux
If there are any dependencies on other packages, apt−get will download and install these supporting packages.
More information can be found in the APT HOWTO.
7.6.3.3. Systems using RPM packages
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, telleng 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.
7.6.4. Upgrading your kernel
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:
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making config changes.
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, e.g.
# root (hd0,0)
# kernel /vmlinuz−version ro root=/dev/hde8
# initrd /initrd−version.img
#boot=/dev/hde default=0
Chapter 7. Home sweet /home 133
Introduction to Linux timeout=10 splashimage=(hd0,0)/grub/splash.xpm.gz
title Red Hat Linux new (2.4.9−31)
root (hd0,0)
kernel /vmlinuz−2.4.9−31 ro root=/dev/hde8
initrd /initrd−2.4.9−31.img
title old−kernel
root (hd0,0)
kernel /vmlinuz−2.4.9−21 ro root=/dev/hde8
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.
7.6.5. Installing extra packages from the installation CDs
7.6.5.1. Mounting a CD
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)
7.6.5.2. Using the CD
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.
7.6.5.3. Ejecting the CD
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
Chapter 7. Home sweet /home 134
Introduction to Linux arguments, which will put you back in your home directory. After that, you can either use the command
umount
/mnt/cdrom
or
eject
cdrom
Blocked drives
NEVER force the drive. The trick with the paperclip is a bad idea, because this will eventually expunge the CD, but your system will think the CD is still there because normal procedures were not followed.
Chances are likely that you will have to reboot to get the system back in a consistent state.
If you keep getting "device busy" messages, check first that all shell sessions have left the CD file system and that no graphical applications are using it anymore. When in doubt, use the lsof tool to trace down the process(es) still using the CD resource.
7.7. 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.
7.8. Exercises
7.8.1. Shell environment
• Print out your environment settings. Which variable may be used to store the CPU type of your machine?
• Make a script that can say something on the lines of "hello, world." Give it appropriate permissions so it can be run. Test your script.
• Create a directory in your home directory and move the script to the new directory. Permanently add this new directory to your search path. Test that the script can be executed without giving a path to its actual location.
• Create subdirectories in your home directory to store various files, for instance a directory music
to keep audio files, a directory documents
for your notes, and so on. And use them!
• Create a personalized prompt.
• Display limits on resource usage. Can you change them?
•
Try to read compressed man pages without decompressing them first.
Chapter 7. Home sweet /home 135
Introduction to Linux
• Make an alias lll which actually executes ls
−la
.
• Why does the command tail
testfile
> testfile
not work?
• Mount a data CD, such as your Linux installation CD, and have a look around. Don't forget to unmount when you don't need it anymore.
•
the script so that it only selects plain files for copying. Use find to make the selection. Do not forget to make the script executable before you try to run it.
7.8.2. Graphical environment
• Try all the mouse buttons in different regions (terminal, background, task bar).
•
Explore the menus.
• Customize your terminal window.
• Use the mouse buttons to copy and paste text from one terminal to another.
• Find out how to configure your window manager; try different workspaces (virtual screens).
• Add an applet, such as a load monitor, to the task bar.
•
Apply a different theme.
• Enable the so−called sloppy focus.
• Switch to a different window manager.
• Log out and select a different session type, like KDE if you were using Gnome before. Repeat the previous steps.
•
Find an audio CD or a DVD or such, and try to play it.
Chapter 7. Home sweet /home 136
ดาวน์โหลด
โฆษณา