Red Hat Certified System Administration 8



Chapter 02: Using Essential Tools


Sommaire

  • Basic Shell Skills
  • Editing Files with vim
  • Understanding the Shell Environment
  • Finding Help


Basic Shell Skills



Red Hat Shells

Available Shells

■ CLI Shells: bash, sh
■ GUI Shells: Gnome, KDE

Default Shells

The default GUI Shell is GNOME
The default CLI Shell is Bash

Shells

  • /bin/bash
  • /bin/csh
  • /bin/sh
  • /bin/tcsh
La liste des shells disponibles sur Red Hat se trouve dans le fichier /etc/shells

[root@redhat ~]# cat /etc/shells

/sbin/nologin (no shell)account in this mode exists but cannot login. We can see account on start page but cannot login. Deny commands execution

GUI Shells

The GNOME desktop environment

The default desktop environment in Red Hat Enterprise Linux 8 is provided by GNOME 3

GNOME: GNU Network Object Model Environment

desktop environments

Two desktop environments provided by Red Hat:
  • GNOME: the default desktop environment
  • KDE: an alternate desktop environment
The X Window System is Linux's graphical subsystem
Xorg is the particular version of the X Window System used by Red Hat

GNU Network Object Model Environment (GNOME)

Nautilus : Gui Filesystem Explorer
Firefox: Web Browser


Bourne-Again Shell (bash)

Bash Prompt components

[user@PCname currentdirectory]$ user bash prompt
[user@PCname ~]$ user bash prompt in user home directory
[root@PCname currentdirectory]# superuser bash prompt

Symbols

. Current directory
.. Parent directory
~ Current User directory

Keyboard Shortcuts

Ctrl+a Jump to the beginning of the command line
Ctrl+e Jump to the end of the command line
Ctrl+u Clear from the cursor to the beginning of the command line
Ctrl+k Clear from the cursor to the end of the command line
Ctrl+r Search the history list of commands for a pattern

Tab : Command Completion
up and Down Keys : Previous commands Browsing


Basic Commands and Operations

[root@lab ~]# ls     List the contents of the current directory
[root@lab ~]# dir List the contents of the current directory
[root@lab ~]# ls -l List the contents of the current directory as well as the properties
[root@lab ~]# ll List the contents of the current directory as well as the properties
[root@lab ~]# vdir List the contents of the current directory as well as the properties
[root@lab ~]# cd directory Change the working directory
[root@lab ~]# pwd Display the working directory
[root@lab ~]# echo text Display a line of text
[root@lab ~]# echo $PATH Display a variable

Time an operation

Syntax
time command
Example
[eninam@localhost ~]$ time pwd
Terminate the shell
[eninam@localhost ~]$ exit
[eninam@localhost ~]$ logout

[root@lab ~]# hostname Dipslay your host machine name
[root@lab ~]# hostname name change your host machine name temporary
[root@lab ~]# reboot restart machine
[root@lab ~]# hostnamectl set-hostname hostname Change System Host name stored in /etc/hostname

Shutdown System

[root@lab ~]# systemctl poweroff

[root@lab ~]# shutdown –option time [+]

[root@lab ~]# init 0

Time

[root@lab ~]# date     display date
[root@lab ~]# cal display calendar
[root@lab ~]# cal month year display calendar
[root@lab ~]# cal 7 2030 display 2030 July calendar
[root@lab ~]# cal 2030 display 2030 calendar
[root@lab ~]# timedatectl display time settings
[root@lab ~]# timedatectl set-time YYYY-MM-DDChange the Current Date (root)
[root@lab ~]# timedatectl set-time 2013-06-02 Change the Current Date (root)
[root@lab ~]# timedatectl set-time HH:MM:SSChanging the Current Time (root)
[root@lab ~]# timedatectl set-ntp true Activate NTP Client
[root@lab ~]# timedatectl set-ntp false Deactivate NTP Client
[root@redhat ~]# timedatectl list-timezones
[root@redhat ~]# timedatectl set-timezone time_zone

Language

Change system language
Syntax
localectl set-locale language-code

Example
[root@localhost eninam]# localectl set-locale LANG=fr_FR.utf8

Language selection for a command
Example
[eninam@localhost ~]$ LANG=fr_FR.utf8 cal Display calendar in french


[root@localhost eninam]# clear erase shell prompt

[root@localhost eninam]# history show user recently used commands


Editing Files with vim



VI Improved (vim)

vi stands for Visual Interface.
VI Improved (vim)

VI IMproved

The version of vi that is shipped with Red Hat Enterprise Linux 7 is called vim. vim stands for VI IMproved, as vim comes with many features not found in the original vi, while still remaining (mostly) backward-compatible. Among the new features are popular options, such as

  • syntax highlighting,
  • completion modes,
  • and spell-checking.

Syntax

[root@lab ~]# vi file

[root@lab ~]# vim options file

■ Open and edit a file.
■ Creates file if it doesn’t exist

Execution modes

Vim functions in three different modes:
  • command mode
  • insert mode
  • last line mode.

Editing Steps

When you first start working with a file, you are in command mode. Here, you can issue commands that allow you to move around your file without actually inserting text into the file.

When you’re ready to insert text into the file, you can use i or a to move into insert mode, enabling you to insert text at the cursor location. To move out of insert mode back into command mode, just press the Esc key.

The last mode you can enter is last line mode, which you enter by typing a colon (:). In this mode, you can issue additional commands to save, quit, and do even more.

esc [key] to quit mode

Commands mode

i insert (insert mode). insert text at the current cursor position
a append (edit at end of line). append text after the current position of the cursor
v (visual) selection
d to cut the selection.
y to copy the selection
yy young (copy a line)
dd delete (cut a line)
p (paste)
P if you want to paste it above the current line
x to delete a single character.
dw to delete the rest of the word. from the current position of the cursor to the end of the word
D to delete from the current cursor position up to the end of the line
o open a new line under the current position of the cursor
O open a new line above the current position of the cursor.
r modify character. put the cursor on the letter and press r. Next type a new letter as a replacement for the letter .
e Moves to the end of a word
b Moves to the beginning of a word
$ Moves to the end of a line
H Moves to the first line onscreen
L Moves to the last line onscreen
a Appends after the cursor
o Opens a new line below and inserts
O Opens a new line above and inserts
R Enters insert mode but replaces characters instead of inserting
dd Deletes the current line
x Deletes text under the cursor
yy Yanks (copies) the current line
p Pastes the yanked line
u Undoes the last action

Last line mode

:set nonumber don’t show lines numbers
:set number show lines numbers
:number go to a line
:q to quit page
:q! to quit page without saving
:w to save page If you want to save it under a new filename, just enter the new name after the w command.
:wq to save and quit page
:/string search a string in file contains
:%s/oldtext/newtext/g replaces oldtext with newtext in the current file


Understanding the Shell Environment


Environment Variables

Commands
[root@lab ~]# env Display all Environment Variables
[root@lab ~]# echo $var show a variable
[root@lab ~]# var = "value" create a local variable
[root@lab ~]# export var add local variable in environment variables
[root@lab ~]# export var = "value" add local variable in environment variables
[root@lab ~]# unset var delete an environment variable

NB: all modifications on environment variables are temporary

Variables

PATH scripts and binaries executables directories
USER Username
LOGNAME connected user
PWD current directory
OLDPWD last visited directory
HOME user personal directory

Example

[root@redhat ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@redhat ~]# export PATH="$PATH:/root/SCRIPTS"
[root@redhat ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/root/SCRIPTS
[root@redhat ~]# table
Saisir la table que vous voulez:
4
TABLE DE MULTIPLICTION PAR 4
4 x 0 = 0
4 x 1 = 4
4 x 2 = 8
4 x 3 = 12
4 x 4 = 16
4 x 5 = 20
4 x 6 = 24
4 x 7 = 28
4 x 8 = 32
4 x 9 = 36
4 x 10 = 40
4 x 11 = 44
4 x 12 = 48

Pour modifier de facon permanente le PATH relatif à un utilisateur il faudrait ajouter la commande export dans son fichier .bashrc

Add this line in the file to use a specific directory as scripts or binary PATH
export PATH="$PATH: directory path"


Finding Help


Helping on Red Hat

The quickest way to get an overview of how to use a command is by running the command with the --help option.

Un certain nombre de commndes disposent cette option mais pas tous

Example

"cd" n'en dispose pas

[root@redhat ~]# cd --help
-bash: cd: --: invalid option
cd: usage: cd [-L|[-P [-e]]] [dir]

Par contre la commande "man" en dispose
[root@redhat ~]# man --help

Help Tools

  • man
  • pinfo
  • info

man command

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.

Syntax

[root@redhat ~]# man options command



[root@redhat ~]# man man
[root@redhat ~]# man 1 man
[root@redhat ~]# man 6 man
No manual entry for man in section 6

[root@redhat ~]# man 2 fork fork is a system call used to make process child

Search with man

[eninam@localhost ~]$ man -k partition

[eninam@localhost ~]$ man -k passwd

[root@redhat ~]# man -k shells
endusershell (3) - get permitted user shells
getusershell (3) - get permitted user shells
pam_shells (8) - PAM module to check for valid login shell
setusershell (3) - get permitted user shells
shells (5) - pathnames of valid login shells

[+]
[root@redhat ~]# apropos shells
endusershell (3) - get permitted user shells
getusershell (3) - get permitted user shells
pam_shells (8) - PAM module to check for valid login shell
setusershell (3) - get permitted user shells
shells (5) - pathnames of valid login shells

le numero entre () indique le type d'informations decrit dans le tableau plus haut

Update man Database

To update man database after adding any new packages:

[root@redhat ~]# mandb

[+]

pinfo Command



Documentation

When the package is installed, files recognized as documentation are moved to /usr/share/doc/package-name

[student@desktopX -]$ firefox file:///usr/share/doc


Red Hat Customer portal

https://access.redhat.com

[student@localhost ~]$ redhat-support-tool

Eninam BAGNABANA     |         |     bagnadavid@outlook.fr     |