Online book on command-line Linux usage, and Gentoo Linux in particular (Turkish Translation Fork) [I didn't continue]
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

572 lines
22 KiB

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
<title>System Management</title>
<para>System management is a broad term. It is my attempt to cover the
system administration tasks that almost every administrator (or end user)
will need to know for his system, such as time management, language
management, keyboard settings and more.</para>
<title>Environment Variables</title>
<para>The Linux operating system makes extensive use of environment
<para>An environment variable<indexterm>
<primary>environment variable</primary>
</indexterm> is a simply a key-value pair which a process can read out.
For instance, the environment variable <varname>EDITOR</varname> (with, as
an example, value <filename>/bin/nano</filename>) informs the process who
reads it that the default text editor is (in this case) nano. These
variables are not system-wide: if you alter the value of a variable, the
change is only active in the session where you are in (which is your shell
and the processes started from the shell).</para>
<title>List of Environment Variables</title>
<para>There are quite a few environment variables you'll come across
<para>The <parameter>DISPLAY</parameter><indexterm>
</indexterm> environment variable is used when you're logged on to a
Unix/Linux system graphically. It identifies where X applications
should "send" their graphical screens to. When you log on to a system
remotely, this variable is set to your local IP address and the screen
number you're using on this system. Most of the time, when you're
logged on locally, it's content is ":0.0" (the first screen on the
<para>Note that "screen" here isn't the hardware device, but a name
given to a running X instance.</para>
<para>The <parameter>EDITOR</parameter><indexterm>
</indexterm> variable identifies the default text editor you want to
use. Applications that spawn a text editor (for instance, visudo) to
edit one or more files, use this variable to know which text editor to
<title>LANG and other locale specific variables</title>
<para>Locales are discussed later in this chapter. Its environment
variables (<parameter>LANG</parameter> and the various
<parameter>LC_*</parameter> variables) identify the users' language,
time zone, currency, number formatting and more.</para>
<para>The PATH variable identifies the directories where the system
should look for executable files (being binaries or shell scripts). If
unset or set incorrectly, you cannot execute a command without
providing the entire path to this command (except built-in shell
commands as those are no executable files).</para>
<para>Below is a small example of a PATH variable:</para>
<programlisting>~$ <command>echo $PATH</command>
<para>An example of what happens when PATH is not set:</para>
<programlisting>~$ <command>ls</command>
(... listing of current directory ...)
~$ <command>unset PATH</command>
~$ <command>ls</command>
-bash: ls: No such file or directory
~$ <command>/bin/ls</command>
(... listing of current directory ...)</programlisting>
<para>The <parameter>TERM</parameter><indexterm>
</indexterm> variable allows command-line programs with special
characters to identify which terminal you use to run them. Although
nowadays the xterm TERM is most used, sometimes you will find yourself
logged on to a different system which doesn't know xterm or where the
application looks really awkward. In such cases a solution could be to
set the TERM variable to, for instance, vt100.</para>
<title>How to Set an Environment Variable</title>
<para>Environment variables are user specific, but can be set on three
levels: session (only valid for the current, open session), user (only
valid for this user and used as default for all sessions of this user)
or system wide (used as a global default).</para>
<title>Session Specific</title>
<para>When you want to set an environment variable for a specific
session, you can use the shell <command>set</command><indexterm>
</indexterm> or <command>export</command><indexterm>
</indexterm> command:</para>
<programlisting>~$ <command>ls -z</command>
ls: invalid option -- z
Try `ls --help` for more information.
~$ <command>export LANG="fr"</command>
~$ <command>ls -z</command>
ls: option invalide -- z
Pour en savoir davantage, faites: `ls --help`</programlisting>
<para>Which one to use depends on what you actually want to
<para>With <command>set</command>, you change the environment
variable for this session, but not for the subshells you might
want to start from the current shell. In other words, set is local
to the shell session.</para>
<para>With <command>export</command>, you change the environment
variable for this session as well as subshells you might want to
start from the current shell from this point onward. In other
words, export is global.</para>
<title>User Specific</title>
<para>User specific environment settings are best placed inside the
</indexterm> file. This file is automatically read when a user is
logged on (at least when he is using the bash shell). A more
shell-agnostic file is <filename>.profile</filename><indexterm>
</indexterm>. Inside the file, define the variables as you would for
a specific session:</para>
<programlisting>export LANG="fr"</programlisting>
<title>System Wide Defaults</title>
<para>To make an environment variable system wide, you must make sure
that your environment variable is stored in a file or location that
every session reads out when it is launched. By convention,
<filename>/etc/profile</filename> is a script in which system wide
environment variables can be placed. Gentoo offers a nice interface
for this: inside <filename>/etc/env.d</filename> you can manage
environment variables in a more structured approach, and the
<command></command> script will then make sure that the
environment variables are stored elsewhere so that
<filename>/etc/profile</filename> reads them out.</para>
<para>The /etc/profile script does not read out all values inside
/etc/env.d itself for (at least) two reasons:</para>
<para>The structure used in /etc/env.d uses a specific
"appending" logic (i.e. variables that are defined several times
do not overwrite each other; instead, their values are appended)
which could be too hard to implement in /etc/profile without too
much overhead. After all, /etc/profile is read by every newly
launched session, so if it took too much time, your system would
start up much slower.</para>
<para>The system administrator might want to make a set of
changes which should be made atomic (for instance, remove a
value from one variable and add it to another). If changes are
publicized immediately, a session could read in /etc/profile
which loads an at that time incorrect environment variable set
(especially when a process is launched after the administrators'
first change but before the second).</para>
<title>Managing Environment Entries</title>
<para>On Linux, the behaviour of many commands is manipulated by values
of environment entries, or environment variables. Within Gentoo Linux,
you can manage the system-wide environment variables through the
<filename>/etc/env.d</filename> directory.</para>
<title>Environment Files</title>
<para>Inside /etc/env.d, you will find environment files which use a
simple key=value syntax. For instance, the /etc/env.d/20java file
defines, amongst other environment variables, the PATH and MANPATH
<programlisting># <command>cat /etc/env.d/20java</command>
<para>With these settings, the value of MANPATH (location where man
will search for its manual pages) and PATH (location where the system
will look for executable binaries every time you enter a command) is
<emphasis>extended</emphasis> with the given values (note that the
variables are not rewritten: their value is appended to the value
previously assigned to the variable).</para>
<para>The order in which variable values are appended is based on the
file name inside <filename>/etc/env.d</filename>. This is why most
files start with a number (as most people find it easier to deal with
order based on numbers, plus that the filenames themselves are still
explanatory to what purpose they serve).</para>
<title>Changing Environment Variables</title>
<para>If you want to change a system variable globally, you can either
add another file to <filename>/etc/env.d</filename> or manipulate an
existing one. In the latter case, you should be aware that application
upgrades automatically update their entries inside
<filename>/etc/env.d</filename> without warning (this location is not
protected, unlike many other configuration locations).</para>
<para>As such, it is advisable to always add your own files rather
than manipulate existing ones.</para>
<para>When you have altered an environment file or added a new one,
you need to call <command>env-update</command><indexterm>
</indexterm> to have Gentoo process the changes for you:</para>
<programlisting># <command>env-update</command></programlisting>
<para>This command will read in all environment files and write the
final result in <filename>/etc/profile.env</filename> (which is
sourced by <filename>/etc/profile</filename>, which is always sourced
when a user logs on).</para>
<title>Location Specific Settings</title>
<para>When I talk about location specific settings, I mean the settings
that your neighbour is most likely to need as well: language settings,
keyboard settings, time zone / currency settings, ... Within the Linux/Unix
environment, these settings are combined in the locale settings and
keyboard settings.</para>
<title>Locale Settings</title>
<para>A <emphasis>locale</emphasis><indexterm>
</indexterm> is a setting that identifies the language, number format,
date/time format, time zone, daylight saving time and currency
information for a particular user or system. This locale information is
stored inside a variable called <parameter>LANG</parameter>; however, it
is possible to switch a particular locale setting to another locale (for
instance, use the American English settings for everything, but currency
to European Euro).</para>
<para>The following table gives an overview of the most important
<title>Locale variables supported on a Linux system</title>
<tgroup cols="2">
<entry>A catch-all setting which identifies the locale for all
possible features. However, individual topics can be overridden
using one of the following variables.</entry>
<entry><parameter>LC_COLLATE</parameter> and
<entry>Character handling (which characters are part of the
alphabet) and (alphabetical) order</entry>
<entry>Applications that use message-based output use this
setting to identify what language their output should be</entry>
<entry>Currency-related settings</entry>
<entry>Formatting of numerical values</entry>
<entry>Time related settings</entry>
<para>There is another variable available as well, called
<parameter>LC_ALL</parameter>. If this variable is set, none of the
above variables is used any more. However, use of this variable is
strongly discouraged.</para>
<para>To get an overview of your locale settings (including a full list
of supported variables), enter the <command>locale</command><indexterm>
</indexterm> command.</para>
<para>The format of a locale variable is as follows:</para>
<para>The settings used in this format are:</para>
<title>List of settings used in a locale definition</title>
<tgroup cols="2">
<entry>Language used. Examples are "en" (English), "nl" (Dutch),
"fr" (French), "zh" (Chinese)</entry>
<entry>Location used. Examples are "US" (United states), "BE"
(Belgium), "FR" (France), "CN" (China)</entry>
<entry>Codeset used. Examples are "utf-8" and
<entry>Modifier used, which allows a different definition of a
locale even when all other settings are the same. Examples are
"euro" and "preeuro" (which has its consequences on the monetary
<para>So, a few examples are:</para>
<para>These settings are read as environment variables (which were
discussed earlier) by the applications. You can mark locales system wide,
but it is advised that this is stored on a per-user basis. As such, I
recommend that you set something like the following in your
<filename>~/.bashrc</filename> file (and in
<filename>/etc/skel/.bashrc</filename> so that newly created user
accounts have this set automatically as well):</para>
<programlisting>$ <command>nano -w ~/.bashrc</command>
# Put your fun stuff here
<title>Keyboard Settings</title>
<para>When you aren't using the default qwerty layout, you'll need to
modify the keyboard mapping setting on your system. Gentoo makes this
easy for you: edit /etc/conf.d/keymaps and set the KEYMAP variable to
the mapping you need:</para>
<programlisting># <command>nano -w /etc/conf.d/keymaps</command>
<para>A list of supported keymaps can be found in the subdirectories of
<para>If you want to test and see if a particular keymap is correct,
load it manually using the <command>loadkeys</command><indexterm>
</indexterm> command:</para>
<programlisting># <command>loadkeys &lt;keymap&gt;</command></programlisting>
<title>Time Settings</title>
<para>To change the system time/date, you can use the
</indexterm> command. For instance, to set the date to september 30th,
2008 and time to 17.34h:</para>
<programlisting># <command>date 093017342008</command></programlisting>
<para>If your system has Internet access, it is wise to install
ntp-supporting tools such as the net-misc/ntp package. With
</indexterm> (and other similar tools), you can use online time servers
to set the time of your system correct to the second.</para>
<programlisting># <command>ntpdate</command></programlisting>
<para>To save the current (operating system) time to your hardware clock,
you can use the <command>hwclock</command><indexterm>
</indexterm> program:</para>
<programlisting># <command>hwclock --systohc</command></programlisting>
<title>System Scheduler</title>
<para>Within Unix/Linux, the default scheduler often used is called
</indexterm>. There are quite a few cron implementations available, such
as the popular <command>vixie-cron</command>, <command>fcron</command>,
<command>bcron</command> and <command>anacron</command>. Once installed,
you start the cron service through an init script (which you most likely
add to the default runlevel):</para>
<programlisting># <command>rc-update add vixie-cron default</command>
# <command>/etc/init.d/vixie-cron start</command></programlisting>
<para>When the cron service is running, every user can define one or more
commands he wants to periodically execute. </para>
<para>To edit your personal scheduling rules, run <command>crontab
<programlisting>$ <command>crontab -e</command></programlisting>
<para>Your current rule file will be shown in the default editor (nano,
vim, ...). A crontab entry has 6 columns:</para>
<title>Crontab columns</title>
<tgroup cols="2">
<entry>Minute of the hour (0-59)</entry>
<entry>Hour of the day (0-23)</entry>
<entry>Day of the month (1-31)</entry>
<entry>Month of the year (1-12 or use names)</entry>
<entry>Day of the week (0-7 or use names. 0/7 are Sunday)</entry>
<entry>Command to execute</entry>
<para>Next to the number representation, you can use ranges (first-last),
summation (1,3,5), steps (0-23/2) and wildcards.</para>
<para>For instance, to execute "<command>ntpdate</command>"
every 15 minutes, the line could look like:</para>
<programlisting>*/15 * * * * ntpdate</programlisting>
<programlisting>0,15,30,45 * * * * ntpdate</programlisting>
<para>If you just want to view the scheduled commands, run
<command>crontab -l</command>.</para>