![]() | Red Hat Certified System Administration 8 |
Chapter 02: Using Essential ToolsSommaireBasic Shell SkillsRed Hat ShellsAvailable Shells■ CLI Shells: bash, sh■ GUI Shells: Gnome, KDE Default ShellsThe default GUI Shell is GNOMEThe default CLI Shell is Bash 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 ShellsThe GNOME desktop environmentThe default desktop environment in Red Hat Enterprise Linux 8 is provided by GNOME 3 GNOME: GNU Network Object Model Environmentdesktop environmentsTwo desktop environments provided by Red Hat:
Xorg is the particular version of the X Window System used by Red Hat GNU Network Object Model Environment (GNOME)Nautilus : Gui Filesystem ExplorerFirefox: 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 ShortcutsCtrl+a Jump to the beginning of the command lineCtrl+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
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
LanguageChange system languageSyntax 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 vimVI Improved (vim)vi stands for Visual Interface.VI Improved (vim) VI IMprovedThe 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[root@lab ~]# vi file[root@lab ~]# vim options file ■ Open and edit a file. ■ Creates file if it doesn’t exist Execution modesVim functions in three different modes:
Editing StepsWhen 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 modeCommands modei insert (insert mode). insert text at the current cursor positiona 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 EnvironmentEnvironment VariablesCommands[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 VariablesPATH scripts and binaries executables directoriesUSER 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 PATHexport PATH="$PATH: directory path" Finding HelpHelping on Red HatThe 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 tousExample "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 commandTo 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 DatabaseTo update man database after adding any new packages: [root@redhat ~]# mandb![]() [+] pinfo Command![]() DocumentationWhen 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 portalhttps://access.redhat.com[student@localhost ~]$ redhat-support-tool |