Chapter2 - Using Essential Tools
Chapter2 - Using Essential Tools
• An alias is a command that a user can define as needed. Some aliases are
provided by default; type alias on the command line to get an overview. To
define an alias.
• Use alias newcommand=’oldcommand’ , as in the default alias ll=’ls -l --
color=auto’ .
Internal Command
• Managing Linux often means working with files. Most of the things that are configured on Linux are
configured through files. To get things done, you often need to change the contents of a configuration
file with a text editor.
• One editor really matters, though, and that is vi
• That is why as a Linux administrator need to know how to work with vi. Only one alternative is
permitted, and that is vim. Vim is “vi improved;” enhancements that make working with vi easier, such
as syntax highlighting for many configuration files which makes it easy to recognize typing errors that
you have made.
• An important concept when working with vim is that it uses different modes. Two of them are
particularly important: command mode and input mode.
Vim Essential Commands
Vim Practice
Understanding the Shell Environment
When a user logs in, an environment is created for that user automatically. This
happens based on four different files where some script code can be specified
and where variables can be defined for use by one specific user:
• /etc/profile: This is the generic file that is processed by all users upon login.
• /etc/bashrc: This file is processed when subshells are started.
• ~/.bash_profile: In this file, user-specific login shell variables can be defined.
• ~/.bashrc: In this user-specific file, subshell variables can be defined.
login shell & Subshell
• A login shell is the first shell that is opened for a user after the user has
logged in. From the login shell, a user may run scripts, which will start a
subshell of that login shell.
• Bash allows for the creation of a different environment in the login shell and
in the subshell but to synchronize settings; by default the subshell settings
are included when entering a login shell.
Using /etc/motd and /etc/issue
• Bash offers an option to include messages in the /etc/motd and the /etc/issue files.
• Messages in /etc/motd display after a user has successfully logged in to a shell.
• (Notice that users in a graphical environment do not see its contents after a graphical
login.)
• Using /etc/motd can be a convenient way for system administrators to inform users.
• Another way to send information to users is by using /etc/issue. The contents of this
file display before the user logs in.
Managing the Shell Environment
Finding Help
• Using –help
The quickest way to get an overview of how to use a command is by running the
command with the --help option.
• Using man
When using the Linux command line, you will at some point consult man pages. Man is what
makes working from the command line doable. If you do not know how a command is used, the
man page of that command will provide valuable insight.
• Finding the Right man Page
To find information in man pages, you can search the mandb database by using apropos or
man -k . If the database is current, getting access to the information you need is easy. Just type
man -k , followed by the keyword you want to search for.
Example of man page
Searching man Pages with man -k
Man pages are categorized in different
sections.
The most relevant sections for system administrators are as follows
• 1: Executable programs or shell commands
• 5: File formats and conventions
• 8: System administration commands
• So, if you are looking for the configuration file that has something to do with passwords, use
man -k password | grep 5
• If you are looking for the command that an administrator would use to create partitions, use
man -k partition | grep 8
• Another useful man option is -f . The command man -f <somecommand> displays a short
description of the item as found in the man database.
Updating mandb
• When using the man -k command, the mandb database is consulted. It can
sometimes happen that you are looking for something that should obviously
be documented but you cannot find anything anyway and all you get is
“nothing appropriate.” If that happens, you might need to update the man
database.
• Just run the mandb command as root without any arguments. It will see
whether new man pages have been installed and update the man database
accordingly.
Exercise Using man -k
Using info
• In this chapter, you read about essential Linux administration tasks. You
learned about some of the important shell basics, such as I/O redirection,
working with history, and management of the environment.
• You also learned how to edit text files with the vim editor. In the last part of
this chapter, you learned how to find information using man and related
commands.