Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
elearning:workbooks:redhat:rh124en:l103 [2024/11/11 10:48] – created admin | elearning:workbooks:redhat:rh124en:l103 [2024/11/26 10:29] (Version actuelle) – admin | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | ~~PDF: | ||
- | |||
Version : **2024.01** | Version : **2024.01** | ||
- | Dernière mise-à-jour | + | Last updated |
- | ======RH12404 - Commandes de Base et de Manipulation | + | ======RH12404 - Basic Shell Commands and Text Manipulation |
- | =====Contenu du Module===== | + | =====Contents===== |
- | * **RH12404 - Commandes de Base et de Manipulation | + | * **RH12404 - Basic Shell Commands and Text Manipulation |
- | * Contenu du Module | + | * Contents |
- | * LAB #1 - 38 Commandes de Base | + | * LAB #1 - Use of Basic Shell Commands |
- | * 1.1 - La commande | + | * 1.1 - The stty Command |
- | * 1.2 - La commande | + | * 1.2 - The date command |
- | * 1.3 - La commande | + | * 1.3 - The who Command |
- | * 1.4 - La commande | + | * 1.4 - The df Command |
- | * 1.5 - La commande | + | * 1.5 - The free Command |
- | * 1.6 - La commande | + | * 1.6 - The whoami |
- | * 1.7 - La commande | + | * 1.7 - The pwd Command |
- | * 1.8 - La commande | + | * 1.8 - The cd Command |
- | * 1.9 - La commande | + | * 1.9 - The ls Command |
- | * 1.10 - La commande | + | * 1.10 - The lsof Command |
- | * 1.11 - La commande | + | * 1.11 - The touch Command |
- | * 1.12 - La commande | + | * 1.12 - The echo Command |
- | * 1.13 - La commande | + | * 1.13 - The cp Command |
- | * 1.14 - La commande | + | * 1.14 - The file Command |
- | * 1.15 - La commande | + | * 1.15 - The cat Command |
- | * 1.16 - La commande | + | * 1.16 - The mv Command |
- | * 1.17 - La commande | + | * 1.17 - The mkdir Command |
- | * 1.18 - La commande | + | * 1.18 - The rmdir Command |
- | * 1.19 - La commande | + | * 1.19 - The rm Command |
- | * 1.20 - La commande | + | * 1.20 - The sort Command |
- | * 1.21 - La commande | + | * 1.21 - The more Command |
- | * 1.22 - La commande | + | * 1.22 - The less Command |
- | * 1.23 - La commande | + | * 1.23 - The find Command |
- | * 1.24 - La commande | + | * 1.24 - The su Command |
- | * 1.25 - Les commandes locate et updatedb | + | * 1.25 - The updatedb |
- | * 1.26 - La commande | + | * 1.26 - The whereis |
- | * 1.27 - La commande | + | * 1.27 - The which Command |
- | * 1.28 - La commande | + | * 1.28 - The uptime |
- | * 1.29 - La commande | + | * 1.29 - The w Command |
- | * 1.30 - La commande | + | * 1.30 - The uname Command |
- | * 1.31 - La commande | + | * 1.31 - The du Command |
- | * 1.32 - La commande | + | * 1.32 - The clear Command |
- | * 1.33 - La commande | + | * 1.33 - The exit Command |
- | * 1.34 - La commande | + | * 1.34 - The logout |
- | * 1.35 - La commande | + | * 1.35 - The sleep Command |
- | * 1.36 - La Commande | + | * 1.36 - The wall Command |
* 1.37 - The seq Command | * 1.37 - The seq Command | ||
- | * 1.38 - La Commande | + | * 1.38 - The screen |
- | * LAB #2 - Options et Arguments | + | * LAB #2 - Switches and Arguments |
- | * LAB #3 - Expressions | + | * LAB #3 - Regular |
- | * ERb | + | * BREs |
- | * ERe | + | * EREs |
- | * Outils de Manipulation de Fichiers Texte | + | * Manipulating Text Files |
- | * Présentation des Commandes grep, egrep et fgrep | + | * Text-search Utilities |
- | * La commande | + | * The grep Command |
- | * La Commande | + | * The egrep Command |
- | * La Commande | + | * The fgrep Command |
- | * LAB #4 - Utiliser | + | * LAB #4 - Using grep, egrep and fgrep |
- | * Présentation de la Commande sed | + | * The Stream EDitor SED |
- | * LAB #5 - Utiliser la Commande | + | * LAB #5 - Using sed |
- | * Présentation de La Commande awk | + | * The Text Processor AWK |
- | * Découpage en champs | + | * Presentation |
- | * Critères | + | * Field Separation |
- | * Une expression | + | * Conditions |
- | * Une expression | + | * A regular |
- | * Une comparaison | + | * A regular |
- | * Un opérateur logique | + | * Comparisons |
- | * Une variable interne | + | * Logical Operators |
- | * Scripts | + | * Built-in Variables |
- | * La Fonction | + | * Awk Scripts |
- | * Structures de Contrôle | + | * The printf |
+ | * Control Statements | ||
* if | * if | ||
* for | * for | ||
* while | * while | ||
* do-while | * do-while | ||
- | * LAB #6 - Utiliser la Commande | + | * LAB #3 - Using awk |
- | * LAB #7 -Autres Commandes Utiles | + | * LAB 7 - Other Useful Commands |
- | * 7.1 - La Commande | + | * 7.1 - The expand |
- | * 7.2 - La Commande unexpand | + | * 7.2 - La Commande unexpand |
- | * 7.3 - La Commande | + | * 7.3 - The cut command |
- | * 7.4 - La Commande | + | * 7.4 - The uniq Command |
- | * 7.5 - La Commande | + | * 7.5 - The tr Command |
- | * 7.6 - La Commande | + | * 7.6 - The paste Command |
- | * 7.7 - La Commande | + | * 7.7 - The split Command |
- | * 7.8 - La Commande | + | * 7.8 - The diff Command |
- | * 7.9 - La Commande | + | * 7.9 - The cmp Command |
- | * 7.10 - La commande | + | * 7.10 - The patch Command |
- | * 7.11 - La commande | + | * 7.11 - The strings |
- | * 7.12 - La commande | + | * 7.12 - The comm Command |
- | * 7.13 - La commande | + | * 7.13 - The head Command |
- | * 7.14 - La commande | + | * 7.14 - The tail Command |
- | * LAB #8 - Utiliser les commandes ifconfig, | + | * LAB #8 - Use the grep, tr and cut commands to extract your IPv4 address from the output of ifconfig |
- | * LAB #9 - Utiliser les commandes ip, grep, awk et sed pour isoler l' | + | * LAB #9 - Use the grep, awk and sed commands to extract your IPv4 address from the output of ip |
- | =====LAB #1 - 38 Commandes de Base===== | + | =====LAB #1 - Use of Basic Shell Commands===== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** - Vous êtes actuellement connecté(e) en tant que root dans votre terminal. | + | **To do** - You are currently the root user in your terminal. |
</ | </ | ||
- | ====1.1 - La commande | + | ====1.1 - The stty Command==== |
- | Dès votre connexion à un système Linux, Il est conseillé de lancer la commande | + | Using this command with the **-a** switch allows you to identify which combination of keys should be used to control a foreground process: |
< | < | ||
Ligne 121: | Ligne 120: | ||
</ | </ | ||
- | Dans l’information qui s’affiche à l’écran, cherchez la chaîne intr =. Si la valeur est «Del», il faut utiliser la touche | + | <WRAP center round important 60%> |
+ | **Important** - The two most important combinations are **intr = ^C** and **susp = ^Z**. The former kills the process whilst the latter suspends its execution. | ||
+ | </ | ||
- | ===Options de la commande=== | + | ===Command Line Switches=== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
- | ====1.2 - La commande | + | ====1.2 - The date command==== |
- | Cette commande affiche la date et l’heure de la machine. La commande peut aussi être utilisée pour régler la date du système | + | This command' |
< | < | ||
Ligne 138: | Ligne 139: | ||
</ | </ | ||
- | ===Options de la commande=== | + | ===Command Line Switches=== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
- | ====1.3 - La commande | + | ====1.3 - The who Command==== |
- | Cette commande affiche les utilisateurs connectés au système: | + | This command' |
< | < | ||
Ligne 153: | Ligne 154: | ||
</ | </ | ||
- | ===Options de la commande=== | + | ===Command Line Switches=== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
- | ====1.4 - La commande | + | ====1.4 - The df Command==== |
- | Cette commande affiche l'espace disque libre sur chacun des unités montés (connectés au système): | + | This command's output shows the free space on each mounted block device: |
< | < | ||
Ligne 175: | Ligne 176: | ||
</ | </ | ||
- | Les unités sont en blocs. Afin d'// | + | The units are shown as **blocks**. In order to **humanize** the output, it is possible to use the **-h** switch: |
< | < | ||
Ligne 189: | Ligne 190: | ||
</ | </ | ||
- | ===Options de la commande=== | + | ===Command Line Switches=== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
- | ====1.5 - La commande | + | ====1.5 - The free Command==== |
- | Cette commande affiche les détails de la mémoire disponible | + | This command' |
< | < | ||
Ligne 206: | Ligne 207: | ||
</ | </ | ||
- | Les unités sont en blocs. Afin d'// | + | The units are shown as **blocks**. In order to **humanize** the output, it is possible |
< | < | ||
Ligne 215: | Ligne 216: | ||
</ | </ | ||
- | ===Options de la commande=== | + | ===Command Line Switches=== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
- | ====1.6 - La commande | + | ====1.6 - The whoami |
- | Cette commande affiche le nom associé à l'UID courant effectif, autrement dit, le nom de votre compte courant | + | This command's output indicates the user name associated with the current effective user ID: |
< | < | ||
Ligne 230: | Ligne 231: | ||
</ | </ | ||
- | Devenez maintenant l' | + | Now become the system administrator |
< | < | ||
[trainee@redhat9 ~]$ su - | [trainee@redhat9 ~]$ su - | ||
- | Password: | + | Password: |
</ | </ | ||
<WRAP center round important 60%> | <WRAP center round important 60%> | ||
- | **Important** : Notez que le mot de passe saisi ne sera PAS visible. | + | **Important** : Note that the password will not be visible. |
</ | </ | ||
- | Saisissez maintenant la commande | + | Now use the **whoami** |
< | < | ||
Ligne 249: | Ligne 250: | ||
<WRAP center round important 60%> | <WRAP center round important 60%> | ||
- | **Important** : Notez maintenant que vous êtes root. | + | **Important** : Note the current effective user ID is root. |
</ | </ | ||
- | Saisissiez en suite la commande | + | Finally execute the **exit** |
< | < | ||
Ligne 260: | Ligne 261: | ||
</ | </ | ||
- | ===Options de la commande=== | + | ===Command Line Switches=== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
- | ====1.7 - La commande | + | ====1.7 - The pwd Command==== |
- | Cette commande affiche le répertoire courant de travail | + | This command' |
< | < | ||
Ligne 275: | Ligne 276: | ||
</ | </ | ||
- | ===Options de la commande=== | + | ===Command Line Switches=== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez la commande | + | **To do** : Use the **help** |
</ | </ | ||
- | ====1.8 - La commande | + | ====1.8 - The cd Command=== |
- | Cette commande permet de changer de répertoire courant pour le répertoire passé en argument | + | This command' |
< | < | ||
[trainee@redhat9 ~]$ cd /tmp | [trainee@redhat9 ~]$ cd /tmp | ||
+ | |||
[trainee@redhat9 tmp]$ pwd | [trainee@redhat9 tmp]$ pwd | ||
/tmp | /tmp | ||
+ | |||
[trainee@redhat9 tmp]$ | [trainee@redhat9 tmp]$ | ||
</ | </ | ||
- | ===Options de la commande=== | + | ===Command Line Switches=== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez la commande | + | **To do** : Use the **help** |
</ | </ | ||
- | ====1.9 - La commande | + | ====1.9 - The ls Command=== |
- | Cette commande permet de lister le contenu d'un répertoire passé en argument | + | This commands output lists information about the files in directory specified as an argument. |
< | < | ||
Ligne 318: | Ligne 321: | ||
</ | </ | ||
- | ===Options de la commande=== | + | ===Command Line Switches=== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
- | ====1.10 - La commande | + | ====1.10 - The lsof Command==== |
- | La commande **lsof** affiche des informations sur les fichiers ouverts par des processus | + | This command' |
< | < | ||
[trainee@redhat9 tmp]$ su - | [trainee@redhat9 tmp]$ su - | ||
Password: fenestros | Password: fenestros | ||
+ | |||
[root@redhat9 ~]# lsof | more | [root@redhat9 ~]# lsof | more | ||
COMMAND | COMMAND | ||
Ligne 362: | Ligne 366: | ||
</ | </ | ||
- | ===Options de la commande=== | + | ===Command Line Switches=== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
- | ====1.11 - La commande | + | ====1.11 - The touch Command==== |
- | Cette commande sert à modifier l' | + | This command updates the access and modification |
< | < | ||
+ | [root@redhat9 ~]# exit | ||
+ | logout | ||
+ | |||
[trainee@redhat9 tmp]$ touch test | [trainee@redhat9 tmp]$ touch test | ||
+ | |||
[trainee@redhat9 tmp]$ ls | [trainee@redhat9 tmp]$ ls | ||
dbus-G7skg3Wlpv | dbus-G7skg3Wlpv | ||
Ligne 390: | Ligne 398: | ||
</ | </ | ||
- | ===Options de la commande=== | + | ===Command Line Switches=== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
- | ====1.12 - La commande | + | ====1.12 - The echo Command |
- | Cette commande écrit les arguments | + | This command writes the arguments |
< | < | ||
Ligne 405: | Ligne 413: | ||
</ | </ | ||
- | ===Options de la commande=== | + | ===Command Line Switches=== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez la commande | + | **To do** : Use the **help** |
</ | </ | ||
- | ====1.13 - La commande | + | ====1.13 - The cp Command=== |
- | La commande cp permet de copier une source vers une destination | + | This command is used to copy a file to a destination |
< | < | ||
[trainee@redhat9 tmp]$ cp test ~ | [trainee@redhat9 tmp]$ cp test ~ | ||
+ | |||
[trainee@redhat9 tmp]$ ls -l ~ | [trainee@redhat9 tmp]$ ls -l ~ | ||
total 4 | total 4 | ||
Ligne 432: | Ligne 441: | ||
<WRAP center round important 60%> | <WRAP center round important 60%> | ||
- | **Important** : Notez l' | + | Note the use of the **~** (tilde) |
</ | </ | ||
- | ===Options de la commande=== | + | ===Command Line Switches=== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
- | ====1.14 - La commande | + | ====1.14 - The file Command==== |
- | Cette commande permet de connaître le type d'un fichier: | + | This command determines a file type: |
< | < | ||
Ligne 451: | Ligne 460: | ||
<WRAP center round important 60%> | <WRAP center round important 60%> | ||
- | **Important** | + | **Important** |
</ | </ | ||
- | Redirigez, en utilisant le caractère **>**, la sortie de la commande | + | Using the <key>></ |
< | < | ||
Ligne 460: | Ligne 469: | ||
</ | </ | ||
- | En utilisant de nouveau la commande | + | Now use the **file** |
< | < | ||
Ligne 467: | Ligne 476: | ||
</ | </ | ||
- | ===Options de la commande=== | + | ===Command Line Switches=== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
- | ====1.15 - La commande | + | ====1.15 - The cat Command==== |
- | La commande **cat** permet de concaténer les fichiers passés en argument, ou de l' | + | This commands concatenate files, or standard |
< | < | ||
Ligne 482: | Ligne 491: | ||
</ | </ | ||
- | ===Options de la commande=== | + | ===Command Line Switches=== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
- | ====1.16 - La commande | + | ====1.16 - The mv Command==== |
- | La commande **mv** permet déplacer ou de renommer un fichier ou répertoire. | + | This command renames a source to a destination or moves sources to a directory: |
- | + | ||
- | Utilisez la commande **mv** pour déplacer le fichier **test** de votre répertoire personnel vers le répertoire courant | + | |
< | < | ||
[trainee@redhat9 tmp]$ mv ~/test . | [trainee@redhat9 tmp]$ mv ~/test . | ||
+ | |||
[trainee@redhat9 tmp]$ ls -l ~ | [trainee@redhat9 tmp]$ ls -l ~ | ||
total 4 | total 4 | ||
Ligne 507: | Ligne 515: | ||
drwxr-xr-x. 2 trainee trainee | drwxr-xr-x. 2 trainee trainee | ||
-rw-r--r--. 1 trainee trainee 442 Sep 25 14:24 vitext | -rw-r--r--. 1 trainee trainee 442 Sep 25 14:24 vitext | ||
+ | |||
[trainee@redhat9 tmp]$ mv test TeSt | [trainee@redhat9 tmp]$ mv test TeSt | ||
+ | |||
[trainee@redhat9 tmp]$ ls -l | [trainee@redhat9 tmp]$ ls -l | ||
total 4 | total 4 | ||
Ligne 526: | Ligne 536: | ||
<WRAP center round important 60%> | <WRAP center round important 60%> | ||
- | **Important** | + | **Important** |
</ | </ | ||
- | ===Options de la commande=== | + | ===Command Line Switches=== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
- | ====1.17 - La commande | + | ====1.17 - The mkdir Command==== |
- | La commande **mkdir** permet de créer un répertoire. | + | This command creates the directory(ies) if it (they) does (do) not exist: |
< | < | ||
[trainee@redhat9 tmp]$ cd ~ | [trainee@redhat9 tmp]$ cd ~ | ||
+ | |||
[trainee@redhat9 ~]$ mkdir testdir | [trainee@redhat9 ~]$ mkdir testdir | ||
+ | |||
[trainee@redhat9 ~]$ ls | [trainee@redhat9 ~]$ ls | ||
Desktop | Desktop | ||
</ | </ | ||
- | ===Options de la commande=== | + | ===Command Line Switches=== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
- | ====1.18 - La commande | + | ====1.18 - The rmdir Command==== |
- | La commande | + | This command removes the directory(ies) if it (they) is (are) **empty**: |
< | < | ||
[trainee@redhat9 ~]$ rmdir testdir | [trainee@redhat9 ~]$ rmdir testdir | ||
+ | |||
[trainee@redhat9 ~]$ ls | [trainee@redhat9 ~]$ ls | ||
Desktop | Desktop | ||
</ | </ | ||
- | ===Options de la commande=== | + | ===Command Line Switches=== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
- | ====1.19 - La commande | + | ====1.19 - The rm Command==== |
- | La commande rm permet de supprimer un répertoire **vide ou non** ou un fichier | + | This command removes a directory, empty or not, as well as files: |
< | < | ||
[trainee@redhat9 ~]$ mkdir testdir1 | [trainee@redhat9 ~]$ mkdir testdir1 | ||
+ | |||
[trainee@redhat9 ~]$ cd /tmp | [trainee@redhat9 ~]$ cd /tmp | ||
+ | |||
[trainee@redhat9 tmp]$ echo " | [trainee@redhat9 tmp]$ echo " | ||
+ | |||
[trainee@redhat9 tmp]$ cd ~ | [trainee@redhat9 tmp]$ cd ~ | ||
+ | |||
[trainee@redhat9 ~]$ mv /tmp/TeSt ~/testdir1 | [trainee@redhat9 ~]$ mv /tmp/TeSt ~/testdir1 | ||
+ | |||
[trainee@redhat9 ~]$ ls -lR testdir1/ | [trainee@redhat9 ~]$ ls -lR testdir1/ | ||
testdir1/: | testdir1/: | ||
total 4 | total 4 | ||
-rw-r--r--. 1 trainee trainee 10 Sep 25 15:08 TeSt | -rw-r--r--. 1 trainee trainee 10 Sep 25 15:08 TeSt | ||
+ | |||
[trainee@redhat9 ~]$ rmdir testdir1/ | [trainee@redhat9 ~]$ rmdir testdir1/ | ||
rmdir: failed to remove ' | rmdir: failed to remove ' | ||
+ | |||
[trainee@redhat9 ~]$ rm -rf testdir1 | [trainee@redhat9 ~]$ rm -rf testdir1 | ||
+ | |||
[trainee@redhat9 ~]$ ls | [trainee@redhat9 ~]$ ls | ||
Desktop | Desktop | ||
</ | </ | ||
- | ===Options de la commande=== | + | ===Command Line Switches=== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
- | ====1.20 - La commande | + | ====1.20 - The sort Command |
- | Cette commande trie dans le canal d’entrée et retourne à l’écran une liste triée. | + | This command writes a sorted concatenation of all files to standard output: |
< | < | ||
[trainee@redhat9 ~]$ touch aac abc bca xyz | [trainee@redhat9 ~]$ touch aac abc bca xyz | ||
+ | |||
[trainee@redhat9 ~]$ ls | [trainee@redhat9 ~]$ ls | ||
+ | |||
aac abc bca Desktop | aac abc bca Desktop | ||
+ | |||
[trainee@redhat9 ~]$ ls | sort | [trainee@redhat9 ~]$ ls | sort | ||
aac | aac | ||
Ligne 617: | Ligne 641: | ||
vitext | vitext | ||
xyz | xyz | ||
+ | |||
[trainee@redhat9 ~]$ ls | sort -r | [trainee@redhat9 ~]$ ls | sort -r | ||
xyz | xyz | ||
Ligne 634: | Ligne 659: | ||
<WRAP center round important 60%> | <WRAP center round important 60%> | ||
- | **Important** | + | **Important** |
</ | </ | ||
- | ===Options de la commande=== | + | ===Command Line Switches=== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
- | ====1.21 - La commande | + | ====1.21 - The more Command |
- | Cette commande affiche le contenu d’un fichier texte et l’envoi | + | This command is used to display a long file page by page: |
< | < | ||
Ligne 680: | Ligne 705: | ||
<WRAP center round important 60%> | <WRAP center round important 60%> | ||
- | **Important** | + | **Important** |
</ | </ | ||
- | ===Options de la commande=== | + | ===Command Line Switches=== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
- | ====1.22 - La commande | + | ====1.22 - The less Command==== |
- | La commande | + | The **less** |
< | < | ||
Ligne 725: | Ligne 750: | ||
</ | </ | ||
- | ===Options de la commande=== | + | ===Command Line Switches=== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
+ | |||
+ | ====1.23 - The find Command=== | ||
- | ====1.23 - La commande find==== | + | This command is used to search for a specific file or directory. The default path is the **current directory** and default expression is **-print**: |
- | + | ||
- | Cette commande sert à rechercher un ou des fichiers dans le répertoire courant ou le répertoire spécifié en argument | + | |
< | < | ||
[trainee@redhat9 ~]$ find acc | [trainee@redhat9 ~]$ find acc | ||
find: ‘acc’: No such file or directory | find: ‘acc’: No such file or directory | ||
+ | |||
[trainee@redhat9 ~]$ find aac | [trainee@redhat9 ~]$ find aac | ||
aac | aac | ||
Ligne 743: | Ligne 769: | ||
<WRAP center round important 60%> | <WRAP center round important 60%> | ||
- | **Important** : Notez que si le fichier n' | + | **Important** : Note that when the file cannot be found, the find command informs you clearly. However when the file is found, the find command just prints the name of the file to standard output. |
</ | </ | ||
- | ===Options de la commande=== | + | ===Command Line Switches=== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
+ | |||
+ | ====1.24 - The su Command=== | ||
- | ====1.24 - La commande su==== | + | This command is used to change the effective user id and group id to that of the user passed as an argument. When executed with no argument, |
- | + | ||
- | La commande su permet d' | + | |
< | < | ||
[trainee@redhat9 ~]$ su - | [trainee@redhat9 ~]$ su - | ||
Password: fenestros | Password: fenestros | ||
+ | |||
[root@redhat9 ~]# | [root@redhat9 ~]# | ||
</ | </ | ||
<WRAP center round important 60%> | <WRAP center round important 60%> | ||
- | **Important** : Notez que le mot de passe saisi ne sera PAS visible. | + | **Important** : Note that the password will not be visible. |
</ | </ | ||
- | ===Options de la commande=== | + | ===Command Line Switches=== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
- | ====1.25 - Les commandes locate et updatedb==== | + | ====1.25 - The updatedb |
- | La commande | + | The **locate** |
- | La commande | + | The default database is **/ |
+ | |||
+ | < | ||
+ | [root@redhat9 ~]# ls -l / | ||
+ | -rw-r-----. 1 root slocate 3436535 Sep 25 15:21 / | ||
+ | </ | ||
+ | |||
+ | |||
+ | <WRAP center round important 60%> | ||
+ | **Important** : For information concerning the database format, please see **man 5 locatedb**. | ||
+ | </ | ||
+ | |||
+ | The **updatedb** | ||
< | < | ||
Ligne 786: | Ligne 825: | ||
</ | </ | ||
- | L' | + | Use of these two commands is very simple: |
< | < | ||
[root@redhat9 ~]# updatedb | [root@redhat9 ~]# updatedb | ||
+ | |||
[root@redhat9 ~]# locate aac | [root@redhat9 ~]# locate aac | ||
/ | / | ||
Ligne 845: | Ligne 885: | ||
</ | </ | ||
- | La base de données par défaut est **/ | + | The default database is **/ |
< | < | ||
Ligne 853: | Ligne 893: | ||
<WRAP center round important 60%> | <WRAP center round important 60%> | ||
- | **Important** : Pour plus d'information | + | **Important**: |
</ | </ | ||
- | ===Options des commandes=== | + | ===Command Line Switches=== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
- | ====1.26 - La commande | + | ==== 1.26 - The whereis |
- | La commande **whereis** permet une recherche de l' | + | This command is used to show the full paths of the executable, the configuration |
< | < | ||
Ligne 871: | Ligne 911: | ||
</ | </ | ||
- | ===Options de la commande=== | + | ===Command Line Switches=== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
- | ====1.27 - La commande | + | ==== 1.27 - The which Command==== |
- | La commande **which** permet une recherche de l' | + | This command searches the PATH variable and returns to standard output the first full path associated with the argument: |
< | < | ||
Ligne 886: | Ligne 926: | ||
</ | </ | ||
- | ===Options de la commande=== | + | ===Command Line Switches=== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
- | ====1.28 - La commande | + | ====1.28 - The uptime |
- | Cette commande nous indique l' | + | This command prints to standard output the current time, the length of time the system has been up, the number of users on the system and the average number of jobs in the run queue over the last 1, 5 and 15 minutes: |
< | < | ||
Ligne 901: | Ligne 941: | ||
</ | </ | ||
- | ===Options de la commande=== | + | ===Command Line Switches=== |
+ | |||
+ | The switches associated with this command are: | ||
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
- | ====1.29 - La commande | + | ====1.29 - The w Command==== |
- | Cette commande reprend les informations de la commande | + | This command outputs the same data as the **uptime** |
< | < | ||
Ligne 918: | Ligne 960: | ||
</ | </ | ||
- | La valeur | + | The JCPU time is the time used by all processes attached to the tty. It does not include past background jobs, but does include currently running background jobs. |
- | La valeur | + | The PCPU time is the time used by the current process, named in the **what** field. |
- | ===Options de la commande=== | + | ===Command Line Switches=== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
- | ====1.30 - La commande | + | ====1.30 - The uname Command==== |
- | Cette commande affiche des informations sur le système | + | This command prints system information to the standard output: |
< | < | ||
[root@redhat9 ~]# uname -a | [root@redhat9 ~]# uname -a | ||
Linux redhat9.ittraining.loc 5.14.0-427.37.1.el9_4.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Sep 13 12:41:50 EDT 2024 x86_64 x86_64 x86_64 GNU/Linux | Linux redhat9.ittraining.loc 5.14.0-427.37.1.el9_4.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Sep 13 12:41:50 EDT 2024 x86_64 x86_64 x86_64 GNU/Linux | ||
+ | |||
[root@redhat9 ~]# uname -s | [root@redhat9 ~]# uname -s | ||
Linux | Linux | ||
+ | |||
[root@redhat9 ~]# uname -n | [root@redhat9 ~]# uname -n | ||
redhat9.ittraining.loc | redhat9.ittraining.loc | ||
+ | |||
[root@redhat9 ~]# uname -r | [root@redhat9 ~]# uname -r | ||
5.14.0-427.37.1.el9_4.x86_64 | 5.14.0-427.37.1.el9_4.x86_64 | ||
+ | |||
[root@redhat9 ~]# uname -v | [root@redhat9 ~]# uname -v | ||
#1 SMP PREEMPT_DYNAMIC Fri Sep 13 12:41:50 EDT 2024 | #1 SMP PREEMPT_DYNAMIC Fri Sep 13 12:41:50 EDT 2024 | ||
+ | |||
[root@redhat9 ~]# uname -m | [root@redhat9 ~]# uname -m | ||
x86_64 | x86_64 | ||
+ | |||
[root@redhat9 ~]# uname -p | [root@redhat9 ~]# uname -p | ||
x86_64 | x86_64 | ||
+ | |||
[root@redhat9 ~]# uname -i | [root@redhat9 ~]# uname -i | ||
x86_64 | x86_64 | ||
+ | |||
[root@redhat9 ~]# uname -o | [root@redhat9 ~]# uname -o | ||
GNU/Linux | GNU/Linux | ||
</ | </ | ||
- | ===Options de la commande=== | + | ===Command Line Switches=== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
- | ====1.31 - La commande | + | ====1.31 - The du Command==== |
- | La commande du peut être utilisée pour afficher la taille des fichiers contenus dans les répertoires passés en arguments. L' | + | This command summarizes disk usage of each file, recursively for directories: |
< | < | ||
Ligne 988: | Ligne 1038: | ||
<WRAP center round important 60%> | <WRAP center round important 60%> | ||
- | **Important** : Notez l' | + | **Important** : Note the use of the **2>/ |
</ | </ | ||
- | ===Options de la commande=== | + | ===Command Line Switches=== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
- | ====1.32 - La commande | + | ==== 1.32 - The clear Command |
- | Cette commande est utilisée pour effacer le contenu de l' | + | This command is used to clear the current screen of the terminal: |
< | < | ||
Ligne 1007: | Ligne 1057: | ||
</ | </ | ||
- | ====1.33 - La commande | + | ==== 1.33 - The exit Command |
- | Cette commande ferme le terminal courant | + | This command exits the current shell: |
< | < | ||
Ligne 1017: | Ligne 1067: | ||
</ | </ | ||
- | ===Options de la commande=== | + | ===Command Line Switches=== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez la commande | + | **To do** : Use the **help** |
</ | </ | ||
- | ====1.34 - La commande | + | ====1.34 - The logout |
- | Cette commande est utilisée pour se déconnecter d'un terminal de connexion en écrivant les données umtp et wmtp dans les fichiers de journalisation. | + | This command logs out a user from a login shell writing the utmp and wtmp entries in the log files. |
- | ===Options de la commande=== | + | ===Command Line Switches=== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez la commande | + | **To do** : Use the **help** |
</ | </ | ||
- | ====1.35 - La commande | + | ====1.35 - The sleep Command |
- | Cette commande pause le terminal pour le nombre de secondes passé en argument | + | This command pauses for a number seconds. The number is specified as the first argument. |
< | < | ||
Ligne 1042: | Ligne 1092: | ||
</ | </ | ||
- | ===Options de la commande=== | + | ===Command Line Switches=== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
- | ====1.36 - La Commande | + | ====1.36 - The wall Command==== |
- | La commande **wall** | + | Wall sends a message |
< | < | ||
[trainee@redhat9 ~]$ su - | [trainee@redhat9 ~]$ su - | ||
Password: fenestros | Password: fenestros | ||
+ | |||
[root@redhat9 ~]# wall this is a message from root | [root@redhat9 ~]# wall this is a message from root | ||
Ligne 1062: | Ligne 1113: | ||
</ | </ | ||
- | Notez que la commande | + | The wall command ignores the TZ environment variable. The time displayed on the first page is based on the system' |
< | < | ||
Ligne 1069: | Ligne 1120: | ||
</ | </ | ||
- | ====1.37 - La Commande | + | ====1.37 - The seq Command==== |
- | La commande | + | The **seq** |
- | | + | * seq [OPTION]... LAST |
- | | + | * seq [OPTION]... FIRST LAST |
- | | + | * seq [OPTION]... FIRST INCREMENT |
- | Par exemple | + | For example |
< | < | ||
Ligne 1091: | Ligne 1142: | ||
9 | 9 | ||
10 | 10 | ||
+ | |||
[root@redhat9 ~]# seq 10 20 | [root@redhat9 ~]# seq 10 20 | ||
10 | 10 | ||
Ligne 1103: | Ligne 1155: | ||
19 | 19 | ||
20 | 20 | ||
+ | |||
[root@redhat9 ~]# seq 20 10 90 | [root@redhat9 ~]# seq 20 10 90 | ||
20 | 20 | ||
Ligne 1114: | Ligne 1167: | ||
</ | </ | ||
- | ===Options de la commande=== | + | ===Command Line Switches=== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
- | ====1.38 - La Commande | + | ====1.38 - The screen |
- | La commande **screen** est un « multiplexeur de terminaux » permettant d' | + | Screen is a full-screen |
- | La commande **screen** n'est pas installée par défaut sous RHEL/CentOS 8. Installez donc le paquet du même nom que la commande à partir du dépôt EPEL : | + | The screen |
< | < | ||
Ligne 1224: | Ligne 1277: | ||
</ | </ | ||
- | Créez maintenant une session | + | Create a session |
< | < | ||
Ligne 1230: | Ligne 1283: | ||
</ | </ | ||
- | Appuyez maintenant sur < | + | Now press the < |
- | Pour repasser au premier | + | To return to the first screen, |
- | Pour voir les screens | + | To see the status of all active |
< | < | ||
Ligne 1243: | Ligne 1296: | ||
</ | </ | ||
- | Dans votre screen, saisissez les commandes suivantes | + | Now enter the following commands: |
< | < | ||
[root@redhat9 ~]# sleep 999 & | [root@redhat9 ~]# sleep 999 & | ||
[1] 3153 | [1] 3153 | ||
+ | |||
[root@redhat9 ~]# jobs -l | [root@redhat9 ~]# jobs -l | ||
[1]+ 3153 Running | [1]+ 3153 Running | ||
+ | |||
[root@redhat9 ~]# | [root@redhat9 ~]# | ||
</ | </ | ||
- | Pour détacher le screen, appuyez sur < | + | In order to detach the current |
< | < | ||
[root@redhat9 ~]# screen -S mysession | [root@redhat9 ~]# screen -S mysession | ||
[detached from 3103.mysession] | [detached from 3103.mysession] | ||
+ | |||
[root@redhat9 ~]# | [root@redhat9 ~]# | ||
</ | </ | ||
- | Pour rattacher le screen, | + | To re-attach the screen, |
< | < | ||
Ligne 1267: | Ligne 1323: | ||
</ | </ | ||
- | <WRAP center round important 60%> | + | Using the jobs command, check if the process created by the sleep command is still running: |
- | **Important** - Vous verrez en tant que titre de votre terminal la chaîne **[screen 0: root@redhat9: | + | |
- | </ | + | |
- | + | ||
- | Utilisez la commande | + | |
< | < | ||
- | [root@redhat9 ~]# screen -ls | ||
- | There is a screen on: | ||
- | 3103.mysession | ||
- | 1 Socket in / | ||
- | [root@redhat9 ~]# sleep 999 & | ||
- | [1] 3153 | ||
- | [root@redhat9 ~]# jobs -l | ||
- | [1]+ 3153 Running | ||
[root@redhat9 ~]# jobs -l | [root@redhat9 ~]# jobs -l | ||
[1]+ 3153 Running | [1]+ 3153 Running | ||
+ | |||
[root@redhat9 ~]# | [root@redhat9 ~]# | ||
</ | </ | ||
- | <WRAP center round important 60%> | + | To move forward or backwards between |
- | Pour naviguer entre les screens | + | |
- | </ | + | |
- | Détachez de nouveau le screen | + | Once again detach the current |
< | < | ||
[root@redhat9 ~]# screen -S mysession | [root@redhat9 ~]# screen -S mysession | ||
[detached from 3103.mysession] | [detached from 3103.mysession] | ||
- | [root@redhat9 ~]# screen -r | + | |
- | [detached from 3103.mysession] | + | [root@redhat9 ~]# |
- | [root@redhat9 ~]# | + | |
</ | </ | ||
- | Créez maintenant un autre screen, cette fois-ci, non imbriqué | + | Now create a new, non-nested screen: |
< | < | ||
Ligne 1307: | Ligne 1349: | ||
</ | </ | ||
- | Constatez le résultat | + | Use the **screen -ls** command to see what has happened: |
< | < | ||
Ligne 1317: | Ligne 1359: | ||
</ | </ | ||
- | Notez cependant que ce screen 0 n'est pas le même que le screen 0 précédent dans lequel vous avez exécuté la commande | + | Note, however, that this screen 0 is not the same as the previous |
< | < | ||
Ligne 1324: | Ligne 1366: | ||
</ | </ | ||
- | Ratachez maintenant le screen | + | To re-attach a specific |
< | < | ||
Ligne 1336: | Ligne 1378: | ||
</ | </ | ||
- | Détachez-vous du screen | + | Once again detach the current |
< | < | ||
- | [root@redhat9 ~]# screen -S mysession | ||
- | [detached from 3103.mysession] | ||
- | [root@redhat9 ~]# screen -r | ||
- | [detached from 3103.mysession] | ||
[root@redhat9 ~]# screen -S mysession1 | [root@redhat9 ~]# screen -S mysession1 | ||
[detached from 3181.mysession1] | [detached from 3181.mysession1] | ||
+ | |||
[root@redhat9 ~]# | [root@redhat9 ~]# | ||
</ | </ | ||
- | Constatez de nouveau le résultat | + | Now check which screen you are connected to: |
+ | |||
+ | < | ||
+ | [root@redhat9 ~]# screen -ls | ||
+ | There are screens on: | ||
+ | 3181.mysession1 (Detached) | ||
+ | 3103.mysession | ||
+ | 2 Sockets in / | ||
+ | </ | ||
+ | |||
+ | Finally, kill the two sessions: | ||
< | < | ||
Ligne 1362: | Ligne 1411: | ||
< | < | ||
[root@redhat9 ~]# screen -XS 3181 quit | [root@redhat9 ~]# screen -XS 3181 quit | ||
+ | |||
[root@redhat9 ~]# screen -ls | [root@redhat9 ~]# screen -ls | ||
There is a screen on: | There is a screen on: | ||
3103.mysession | 3103.mysession | ||
1 Socket in / | 1 Socket in / | ||
+ | |||
[root@redhat9 ~]# screen -XS 3103 quit | [root@redhat9 ~]# screen -XS 3103 quit | ||
+ | |||
[root@redhat9 ~]# screen -ls | [root@redhat9 ~]# screen -ls | ||
No Sockets found in / | No Sockets found in / | ||
Ligne 1372: | Ligne 1424: | ||
</ | </ | ||
- | ===Options de la commande=== | + | ===Command Line Switches=== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
- | =====LAB #2 - Options et Arguments===== | + | =====LAB #2 - Switches and Arguments===== |
- | Les options sous Linux peuvent être exprimées au format court ou au format | + | Switches under Linux can either be short or long. Several differences are important to note. |
- | Premièrement les options | + | Firstly short options |
- | Un exemple est l'option | + | An example is the help option |
* -h | * -h | ||
* --help | * --help | ||
- | Deuxièmement les options courtes peuvent être combinées tandis que les options longues ne peuvent pas l' | + | Secondly, Linux short switches can be combined whereas long switches cannot be combined. For example |
< | < | ||
Ligne 1462: | Ligne 1514: | ||
</ | </ | ||
- | La commande | + | However |
< | < | ||
Ligne 1494: | Ligne 1546: | ||
<WRAP center round important 60%> | <WRAP center round important 60%> | ||
- | **Important** | + | **Important** |
</ | </ | ||
- | =====LAB #3 - Expressions | + | =====LAB #3 - Regular |
- | La manipulation de fichiers textes utilise des **expressions régulières**. Sous Linux il existe deux types d' | + | Text files play a very important role under Linux. For example, almost all configuration files are simple text files and being able to manipulate them is of great importance. Manipulating text files is essentially achieved by using **Regular Expressions**. There are two types of Regular Expressions: |
- | * expressions régulières basiques - IEEE POSIX Basic Regular Expressions, appelées | + | * The IEEE POSIX Basic Regular Expressions |
- | * utilisées par les commandes | + | * The IEEE POSIX Extended Regular Expressions |
- | * expressions régulières étendues - IEEE POSIX Extended Regular Expressions, appelées | + | |
- | * utilisées par les commandes | + | |
- | Les expressions régulières utilisent des caractères spéciaux. Certains caractères sont communs aux Erb et aux Ere : | + | Regular Expressions use **Metacharacters**. Certain are common to both BREs and EREs: |
- | ^Caractère spécial | + | ^Metacharacter |
- | | %%^%% | Trouver la chaîne au début de la ligne | | + | | **%%^%%**// |
- | | $ | Trouver la chaîne à la fin de la ligne | | + | | // |
- | | \ | Annuler l' | + | | **\**// |
- | | [ ] | Trouver n' | + | | **[**// |
- | | [%%^%%] | Exclure les caractères entre crochets | + | | **[%%^%%**// |
- | | . | Trouver n' | + | | **.** | Match any character except when at the end of a line | |
- | | * | Trouver | + | | // |
- | | \< | Trouver la chaîne au début d'un mot | | + | | \< | Match //string// at the beginning of a word | |
- | | \> | Trouver la chaîne à la fin d'un mot | | + | | \> | Match //string// at the end of a word | |
- | ====ERb==== | + | ===BREs=== |
- | Certains caractères spéciaux sont spécifiques aux ERb : | + | Certain Metacharacters are specific to BREs: |
- | ^Caractère spécial | + | ^Metacharacter |
- | | \{x,y\} | Trouver de **x** à **y** occurrences | + | | **\{x,y\}** | Match from **x** to **y** occurrences |
- | | \{x\} | Trouver exactement le nombre | + | | **\{x\}** | Match exactly |
- | | \{x,\} | Trouver le nombre | + | | **\{x,\}** | Match **x** or more occurrences |
- | | \(ERb) | Mémoriser une ERb | | + | | \(BRE) | Commit to memory the BRE | |
- | | \1 | Rappeler la première ERb mémorisée | + | | \1 | Recall the first BRE committed to memory |
- | | \2, \3 ... | Rappeler la deuxième ERb mémorisée, rappeler la troisième ERb mémorisée etc | | + | | \2, \3 ... | Recall the second BRE committed to memory, recall the third BRE committed to memory ... | |
- | ====ERe==== | + | ===EREs=== |
- | Certains caractères spéciaux sont spécifiques aux ERe : | + | Certain Metacharacters are specific to EREs: |
- | ^Caractère spécial | + | ^Metacharacter |
- | | ? | Trouver 0 ou 1 occurrence de ce qui précède | | + | | {x,y} | Match from **x** to **y** occurrences |
- | | + | Trouver 1 ou **n** d' | + | | {x} | Match exactly |
- | | {x,y} | Trouver de **x** à **y** occurrences | + | | {x,} | Match **x** or more occurrences |
- | | {x} | Trouver exactement le nombre | + | | ? | Matches 0 or 1 occurrence of the preceeding element |
- | | {x,} | Trouver le nombre | + | | + | Matches 1 or more occurrence(s) of the preceeding element |
- | | () | Faire un **ET** des expressions régulières entre les paranthèses | + | | %%|%% | Matches either the expression before or the expression after the operator | |
- | | %%|%% | Faire un **OU** des expressions régulières se trouvant de chaque côté du pipe | | + | | () | Combines the Reguler Expressions between the parentheses |
- | =====Outils de Manipulation de Fichiers Texte===== | + | =====Manipulating Text Files===== |
- | ====Présentation des Commandes grep, egrep et fgrep==== | + | ====Text-search Utilities==== |
- | ===La commande | + | ===The grep Command=== |
- | La commande | + | The **grep** command can be used to find lines containing a string of characters in a group of files. The **-v** or **--invert-case** option can be stipulated to find lines that do **not** contain the specified string. |
- | Par défaut, la commande | + | The grep command is case sensitive. The **-i** |
- | La commande | + | The grep command can also use **BREs**. |
- | La commande grep peut être utilisée avec des **Expressions Régulières basiques**. Ceci est utile pour rechercher dans le contenu de fichiers. | + | ==Command Line Switches== |
- | + | ||
- | ==Options de la commande== | + | |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
- | ===La Commande | + | ===The egrep Command=== |
- | La commande | + | The **egrep** |
- | ==Options de la commande== | + | ==Command Line Switches== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
- | ===La Commande | + | ===The fgrep Command=== |
- | La commande | + | The **fgrep** |
- | + | ||
- | ==Options de la commande== | + | |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
- | ===LAB #4 - Utiliser | + | ===LAB #4 - Using grep, egrep and fgrep=== |
- | Creéz le fichier **/ | + | Create the following file: |
< | < | ||
[root@redhat9 ~]# cd /tmp | [root@redhat9 ~]# cd /tmp | ||
+ | |||
[root@redhat9 tmp]# vi greptest | [root@redhat9 tmp]# vi greptest | ||
+ | |||
[root@redhat9 tmp]# cat greptest | [root@redhat9 tmp]# cat greptest | ||
fenestrOS | fenestrOS | ||
Ligne 1601: | Ligne 1649: | ||
</ | </ | ||
- | Recherchez maintenant toute ligne du fichier **/ | + | |
+ | Now use grep to search for lines containing at least one uppercase or lowercase letter: | ||
< | < | ||
Ligne 1612: | Ligne 1661: | ||
</ | </ | ||
- | Recherchez maintenant toute ligne contenant au moins une lettre ou un chiffre | + | Next use grep to search for lines containing at least one uppercase or lowercase letter or a number: |
< | < | ||
Ligne 1624: | Ligne 1673: | ||
</ | </ | ||
- | <WRAP center round important 60%> | + | To search for the NNN-NNNN |
- | **Important** : Notez la présence de la ligne 555-5555. | + | |
- | </ | + | |
- | + | ||
- | Recherchez maintenant toute ligne contenant un numéro de téléphone au format | + | |
< | < | ||
Ligne 1635: | Ligne 1680: | ||
</ | </ | ||
- | Recherchez maintenant toute ligne contenant exactement un caractère | + | Lines containing just one character have that character both at the beginning (**^**) and at the end (**$**) of the line: |
< | < | ||
Ligne 1643: | Ligne 1688: | ||
</ | </ | ||
- | <WRAP center round important 60%> | + | To search for a line containing a special character such as **.**, that character needs to be preceded by **\**: |
- | **Important** : Notez l' | + | |
- | </ | + | |
- | + | ||
- | Recherchez maintenant toute ligne commençant par un point : | + | |
< | < | ||
Ligne 1656: | Ligne 1697: | ||
<WRAP center round important 60%> | <WRAP center round important 60%> | ||
- | **Important** | + | **Important** |
- | </ | + | |
- | + | ||
- | <WRAP center round important 60%> | + | |
- | **Important** : La commande | + | |
</ | </ | ||
- | Modifiez le fichier **/tmp/greptest** selon l' | + | Make the following changes to the greptest |
< | < | ||
Ligne 1683: | Ligne 1720: | ||
</ | </ | ||
- | Utilisez maintenant la commande | + | Now use the **grep** |
< | < | ||
Ligne 1697: | Ligne 1734: | ||
<WRAP center round important 60%> | <WRAP center round important 60%> | ||
- | **Important** | + | **Important** |
</ | </ | ||
- | Utilisez maintenant la commande | + | Now use the **egrep** |
< | < | ||
Ligne 1715: | Ligne 1752: | ||
<WRAP center round important 60%> | <WRAP center round important 60%> | ||
- | **Important** : Cette commande est particulièrement utile face à un fichier de configuration | + | **Important**: |
</ | </ | ||
- | Modifiez le fichier **/tmp/greptest** selon l' | + | Make the following changes to the greptest |
< | < | ||
[root@redhat9 tmp]# vi greptest | [root@redhat9 tmp]# vi greptest | ||
+ | |||
[root@redhat9 tmp]# cat greptest | [root@redhat9 tmp]# cat greptest | ||
# Starting comment | # Starting comment | ||
Ligne 1739: | Ligne 1777: | ||
</ | </ | ||
- | Utilisez maintenant la commande **fgrep** pour rechercher la ligne commençant par le caractère | + | Now use fgrep to match the line starting with the **^** character: |
< | < | ||
Ligne 1746: | Ligne 1784: | ||
</ | </ | ||
- | Comparez le résultat ci-dessus avec celui de la commande | + | Compare the above output to that when using the grep command: |
< | < | ||
Ligne 1766: | Ligne 1804: | ||
</ | </ | ||
- | La ligne de commande en utilisant la commande | + | As you can see, grep matched **every** line that had a // |
< | < | ||
Ligne 1773: | Ligne 1811: | ||
</ | </ | ||
- | ====Présentation de la Commande sed==== | + | ====The Stream EDitor SED==== |
- | La commande | + | **sed** |
- | + | ||
- | Si plusieurs actions sont spécifiées dans la ligne de commande, chacune doit être précédée par l' | + | |
- | + | ||
- | La syntaxe de la commande sed est la suivante | + | |
< | < | ||
- | sed [adresse] commande | + | sed [address] command |
</ | </ | ||
- | L' | + | The specified commands are applied to each line in the file unless an //address// is specified. Sed prints all results to standard output and does not modify the source file. The address therefore specifies which lines are concerned by the command. |
- | La syntaxe d'une adresse peut être : | + | sed's addresses are as follows: |
- | ^adresse | + | ^address |
- | | a | La ligne numéro | + | | x | Line number |
- | | $ | La dernière ligne | | + | | $ | The last line of the file | |
- | | /ERb/ | Les lignes qui correspondent à l' | + | | /BRE/ | Lines matching the specified BRE | |
- | | a,b | De la ligne numéro | + | | x,y | From line **x** to line **y** | |
- | | /ERb1/, /ERb2/ | Toutes les lignes entre la première occurrence correspondant à l'ERb1 jusqu' | + | | /ERb1/, /ERb2/ | All lines from the first line that matches the first BRE to the first line that matches the second BRE | |
- | Le commandes de sed sont : | + | sed's commands are as follows: |
- | ^commande | + | ^command |
- | | d | Ne pas afficher la ou les ligne(s) | | + | | d | Do not show the matching line(s) on standard output |
- | | p | Afficher la ou les ligne(s) | | + | | p | Show the matching line(s) on standard output |
- | | s | Effectuer une substitution | | + | | s | Do a substitution |
- | | w | Ecrire le ou les ligne(s) dans un fichier | + | | w | Write the matching line(s) to a file | |
- | | = | Afficher le numéro de la ligne spécifiée | + | | = | Print the matching line's number |
- | | ! | Exécuter la commande ci-dessus sur toutes les lignes sauf celle spécifiées dans l' | + | | ! | Exclude the line(s) matching the address |
- | ===Options de la commande=== | + | ===Command Line Switches=== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
- | ===LAB #5 - Utiliser la Commande | + | ===LAB #5 - Using sed=== |
- | La commande **d** de sed permet de ne pas afficher certaines lignes à l' | + | Start by displaying the contents of the file **/ |
< | < | ||
Ligne 1841: | Ligne 1875: | ||
systat | systat | ||
daytime | daytime | ||
- | --Plus-- | + | --More-- |
</ | </ | ||
- | Dans l' | + | Now display the same file without any commented lines: |
< | < | ||
Ligne 1871: | Ligne 1905: | ||
ftp | ftp | ||
ftp | ftp | ||
- | --Plus-- | + | --More-- |
</ | </ | ||
<WRAP center round important 60%> | <WRAP center round important 60%> | ||
- | **Important** : Notez que l'ERb est entourée des caractères / et /. | + | **Important**: |
</ | </ | ||
- | La commande sed vous permet d' | + | Continue by trying to just display the first two lines of **/etc/passwd**: |
< | < | ||
Ligne 1893: | Ligne 1927: | ||
<WRAP center round important 60%> | <WRAP center round important 60%> | ||
- | **Important** : Notez que sed affiche également tout le contenu du fichier. Ceci implique que les lignes 1 et 2 s' | + | **Important**: |
</ | </ | ||
- | Pour n' | + | To force sed to **only** display the lines you specify, use the **-n** |
< | < | ||
Ligne 1904: | Ligne 1938: | ||
</ | </ | ||
- | La commande | + | Now you want to use sed to strip out the comments from **/ |
< | < | ||
[root@redhat9 ~]# sed -n '/ | [root@redhat9 ~]# sed -n '/ | ||
+ | |||
[root@redhat9 ~]# more / | [root@redhat9 ~]# more / | ||
Ligne 1932: | Ligne 1967: | ||
ftp | ftp | ||
ftp | ftp | ||
- | --Plus--(0%) | + | --More--(0%) |
</ | </ | ||
- | La commande | + | <WRAP center round important 60%> |
+ | **Important**: In the above command, we start by matching all lines in the / | ||
+ | </ | ||
+ | |||
+ | Finally, create a file containing **user1, | ||
< | < | ||
Ligne 1944: | Ligne 1983: | ||
<WRAP center round important 60%> | <WRAP center round important 60%> | ||
- | **Important** : Notez que dans cet exemple, la commande | + | **Important**: |
</ | </ | ||
- | ====Présentation de La Commande awk==== | + | ====The Text Processor AWK==== |
- | Le processeur de texte **awk** est un **filtre**. Une **action** awk est fournie sur la ligne de commande entourée de ' ou de " : | + | ===Presentation=== |
- | < | + | The **awk** command acts as a **filter** and uses the following syntax: |
- | awk [-F séparateur] ' | + | |
- | </ | + | |
- | <WRAP center round important 60%> | + | awk [-F seperator] ' |
- | **Important** : Le couple critère | + | |
- | </ | + | |
- | Dans le cas de l' | + | ===Field Separation=== |
- | <file> | + | A file or a text stream is treated by awk as a sequence of records. By default each line is a record. Awk analyzes each record, separating that record into fields and then storing the record and fields in variables: |
- | awk [-F séparateur] -f script [fichier1 | + | |
- | </ | + | |
- | ===Découpage en champs=== | + | * $0 contains the record, |
+ | * $1 contains the first field, | ||
+ | * $2 contains the second field, | ||
+ | * e.t.c. | ||
- | awk sait identifier les champs de la ligne soit parce que ceux-ci sont séparés par un espace ou par une tabulation soit parce que la ligne de commande lui a identifié le séparateur grâce à l' | + | Awk interprets |
- | awk stocke les informations de la ligne dans des variables : | + | Awk then checks if the condition is met for each record and if so, executes the action. |
- | + | ||
- | ^ Variable ^ Description ^ | + | |
- | | $0 | Contient toute la ligne | | + | |
- | | $1, $2 ... | Contient le premier champ de la ligne, contient le deuxième champ de la ligne ... | | + | |
- | Par exemple | + | For example, the following command takes the standard output of **ls -l** and prints fields 8, 3 and 4 to standard output: |
< | < | ||
Ligne 1987: | Ligne 2019: | ||
</ | </ | ||
- | Comme vous pouvez constater, awk a extrait du résultat de la commande **ls -l** les champs **nom de l' | + | Since there is no condition, the action is applied to every record. |
- | Afin de le rendre un peu plus lisible, saisissez la commande suivante | + | To make the output easier to read, you can include spaces between each field: |
< | < | ||
Ligne 2001: | Ligne 2033: | ||
</ | </ | ||
- | ===Critères=== | + | === Conditions |
- | Les **critères** conditionnent l' | + | ==A regular expression applied to a record== |
- | Plusieurs types de critères sont possibles. Les plus utilisées sont les suivantes | + | * Format: |
+ | * /regular expression/ {action} | ||
+ | * Exemple: | ||
+ | * /hello/ {print $0} | ||
- | == Une expression | + | ==A regular |
- | | + | |
- | | + | * $n ~/regular |
- | * Exemple: | + | * $n!~/ |
- | | + | * Examples: |
+ | * $1 ~/hello/ {print $0} | ||
+ | | ||
- | ==Une expression régulière valide pour un champ== | + | ==Comparisons== |
+ | |||
+ | * Format: | ||
+ | * $n operator criteria {action} | ||
+ | * Example: | ||
+ | * $1 > 20 {print $0} | ||
- | | + | **Operators** |
- | * $n ~/ | + | |
- | * $n!~/ | + | |
- | | + | |
- | * $1 ~/ERe/ {print $0} | + | |
- | * $1!~/ERe/ {print $0} | + | |
- | awk sélectionne des lignes en utilisant un opérateur de correspondance ou de non-correspondance : | + | ^ Operator ^ Condition ^ |
+ | | < | Less than | | ||
+ | | <= | Less than or equal to | | ||
+ | | == | Equal to | | ||
+ | | != | Different | | ||
+ | | > | Greater than | | ||
+ | | >= | Greater than or equal to | | ||
- | ^ Opérateur ^ Condition ^ | ||
- | | ~ | Correspondance | | ||
- | | !~ | Non-correspondance | | ||
- | ==Une comparaison== | + | ==Logical Operators== |
- | | + | |
- | | + | * test1 logical operator test2 {action} |
- | * Exemple: | + | * Example: |
- | | + | * $1 ~/hello/ && $2 > 20 {print $0} |
- | Les opérateurs sont : | + | **Operators** |
- | ^ Opérateur | + | ^ Operator |
- | | < | Inférieur | | + | | %%||%% | OR | |
- | | %%<=%% | Inférieur ou égal | | + | | && |
- | | == | Egal | | + | | ! | NO | |
- | | != | Différent | | + | |
- | | > | Supérieur | | + | |
- | | >= | Supérieur ou égal | | + | |
+ | ==Built-in Variables== | ||
- | == Un opérateur logique== | + | * Format: |
+ | * expression1, | ||
+ | * Example: | ||
+ | * NR==7, NR==10 {print $0} | ||
- | | + | **Variables** |
- | * test1 opérateur logique test2 {action} | + | |
- | | + | |
- | * $1 ~/ERe/ && $2 > 20 {print $0} | + | |
- | + | ||
- | Les opérateurs sont : | + | |
- | + | ||
- | ^ Opérateur logique ^ Condition ^ | + | |
- | | %%||%% | OU | | + | |
- | | && | ET | | + | |
- | | ! | NON | | + | |
- | + | ||
- | ==Une variable interne== | + | |
- | + | ||
- | * Format: | + | |
- | * expression1, | + | |
- | * Exemple: | + | |
- | * NR==7, NR==10 {print $0} | + | |
- | + | ||
- | Les variables sont : | + | |
^ Variable ^ Description ^ | ^ Variable ^ Description ^ | ||
- | | NR | Nombre total de lignes | + | | NR | Total number of records |
- | | NF | Nombre total de champs | + | | NF | Total number of fields |
- | | FILENAME | Le nom du fichier en entrée | + | | FILENAME | Name of current input file | |
- | | FS | Le séparateur de champs en entrée. Par défaut un **espace** ou une **tabulation** | | + | | FS | The field separator, by default a **space** or **tab** | |
- | | RS | Le séparateur de lignes en entrée. Par défaut une **nouvelle ligne** | | + | | RS | The record separator, by default |
- | | OFS | Le séparateur de champs en sortie. Par défaut un **espace** | | + | | OFS | Output field separator, by default a **space** | |
- | | ORS | Le séparateur de lignes en sortie. Par défaut une **nouvelle ligne** | | + | | ORS | Output record separator, by default |
- | | OFMT | Le format | + | | OFMT | Numeric output |
- | ===Scripts | + | ===Awk Scripts=== |
- | Quand un programme awk comporte plusieurs **clauses** composées de **critères** et d'**actions**, il convient de d' | + | To combine several //clauses// composed of // |
- | * La section | + | * **BEGIN** |
- | * Cette section | + | * This section |
- | * La section | + | |
- | * Cette section contient les clauses | + | * This sections contains the clauses |
- | * La section | + | * **END** |
- | * Cette sectione est exécutée une fois à la fin du script | + | * This section is executed once, after executing the body of the script |
- | Par exemple | + | For example: |
< | < | ||
[root@redhat9 tmp]# cat > scriptawk | [root@redhat9 tmp]# cat > scriptawk | ||
BEGIN { | BEGIN { | ||
- | print "Liste des systèmes de fichiers montés"} | + | print "List of mounted filesystems"} |
{print $0} | {print $0} | ||
END { | END { | ||
Ligne 2103: | Ligne 2125: | ||
</ | </ | ||
- | <WRAP center round important 60%> | + | Now apply the awk script to **/etc/fstab** : |
- | **Important** : Dans l' | + | |
- | </ | + | |
- | + | ||
- | Ensuite saisissez la commande suivante | + | |
< | < | ||
[root@redhat9 tmp]# awk -f scriptawk /etc/mtab | [root@redhat9 tmp]# awk -f scriptawk /etc/mtab | ||
- | Liste des systèmes de fichiers montés | + | List of mounted filesystems |
sysfs /sys sysfs rw, | sysfs /sys sysfs rw, | ||
proc /proc proc rw, | proc /proc proc rw, | ||
Ligne 2151: | Ligne 2169: | ||
<WRAP center round important 60%> | <WRAP center round important 60%> | ||
- | **Important** : Notez l' | + | **Important**: |
</ | </ | ||
- | ===La Fonction | + | ===The printf |
- | La fonction intégrée | + | The integrated function |
< | < | ||
- | printf ("chaine", | + | printf ("string", |
</ | </ | ||
- | **chaine** contient autant de formats | + | **string** contains as many formats |
- | Les formats | + | Examples of formats |
^ Format ^ Description ^ | ^ Format ^ Description ^ | ||
- | | %30s | Affichage d'une chaîne (s=string) sur 30 positions avec cadrage à droite | + | | %30s | Displays a right-justified |
- | | %-30s | Affichage d'une chaîne (s=string) sur 30 positions avec cadrage à gauche | + | | %-30s | Displays a left-justified |
- | | %4d | Affichage d'un entier sur 4 positions avec cadrage à droite | + | | %4d | Displays a right-justified decimal number of 4 digits |
- | | %-4d | Affichage d'un entier sur 4 positions avec cadrage à gauche | + | | %-4d | Displays a left-justified decimal number of 4 digits |
- | ===Structures de Contrôle=== | + | ===Control Statements=== |
- | awk peut utiliser des structures de contrôle. | + | awk can use the following control statements: |
==if== | ==if== | ||
- | |||
- | La syntaxe de la commande if est la suivante : | ||
< | < | ||
if condition { | if condition { | ||
- | | + | |
- | | + | |
... | ... | ||
} | } | ||
Ligne 2190: | Ligne 2206: | ||
else { | else { | ||
- | | + | |
- | | + | |
... | ... | ||
} | } | ||
Ligne 2197: | Ligne 2213: | ||
</ | </ | ||
- | ou dans le cas d'une seule commande | + | or: |
< | < | ||
if condition | if condition | ||
- | | + | |
else | else | ||
- | | + | |
</ | </ | ||
==for== | ==for== | ||
- | |||
- | La syntaxe de la structure de contrôle **for** est la suivante : | ||
< | < | ||
- | for variable in liste_variables | + | for variable in list { |
- | | + | |
- | | + | |
... | ... | ||
Ligne 2224: | Ligne 2238: | ||
</ | </ | ||
- | ou dans le cas d'une seule commande | + | or: |
< | < | ||
- | for variable in liste_variables | + | for variable in list |
- | | + | |
</ | </ | ||
- | ou dans le cas d'un tableau | + | or in the case of a table: |
< | < | ||
- | for clef dans tableau | + | for key in table { |
- | print clef , tableau[clef] | + | print key , table[key] |
} | } | ||
Ligne 2244: | Ligne 2258: | ||
==while== | ==while== | ||
- | |||
- | La syntaxe de la structure de contrôle **while** est la suivante : | ||
< | < | ||
while condition { | while condition { | ||
- | commande | + | command |
- | commande | + | command |
... | ... | ||
Ligne 2258: | Ligne 2270: | ||
==do-while== | ==do-while== | ||
- | |||
- | La syntaxe de la structure de contrôle **do-while** est la suivante : | ||
< | < | ||
do { | do { | ||
- | commande | + | command |
- | commande | + | command |
... | ... | ||
Ligne 2271: | Ligne 2281: | ||
</ | </ | ||
- | ===Options de la commande=== | + | ===Command Line Switches=== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
- | ===LAB #6 - Utiliser la Commande | + | ===LAB #6 - Using awk=== |
- | Pour illustrer l' | + | Create the file **sales.txt**: |
< | < | ||
Ligne 2304: | Ligne 2314: | ||
</ | </ | ||
- | Ce fichier contient des statistiques de vente par type de PC et par département. | + | Now create the awk script |
- | + | ||
- | Créez maintenant le script | + | |
< | < | ||
[root@redhat9 tmp]# vi sales.awk | [root@redhat9 tmp]# vi sales.awk | ||
+ | |||
[root@redhat9 tmp]# cat sales.awk | [root@redhat9 tmp]# cat sales.awk | ||
# BEGIN | # BEGIN | ||
Ligne 2326: | Ligne 2335: | ||
</ | </ | ||
- | Ce script | + | This script |
< | < | ||
Ligne 2344: | Ligne 2353: | ||
</ | </ | ||
- | Dans ce script | + | It is important that you understand the key lines in the above script: |
- | * La ligne **3**, | + | * Line **3**, |
- | * Cette ligne se trouve dans la section | + | * Defines a new field seperator in a BEGIN section. |
- | * La ligne **6**, | + | * Line **6**, |
- | * Cette ligne évite le traitement de toute ligne commençant par le caractère **#** ainsi que toute ligne vide. | + | * Discards all commented and empty lines. |
- | * La ligne **7**, | + | * Line **7**, |
- | * Ce tableau a pour clef la valeur de **$1**, | + | * The table' |
- | * La ligne **11**, | + | * Line **12**, |
- | * Cette ligne démarre une boucle **for**.7 | + | * Uses printf |
- | * La ligne **12**, | + | |
- | * Cette ligne utilise **printf** afin d' | + | |
- | Appliquez maintenant votre script | + | Now execute the script |
< | < | ||
Ligne 2367: | Ligne 2374: | ||
</ | </ | ||
- | ====LAB #7 -Autres Commandes Utiles==== | + | ====LAB #7 - Other Useful Commands==== |
- | ===7.1 - La Commande | + | ===7.1 - The expand |
- | La commande | + | The **expand** |
- | Créez le fichier **expand** | + | Create the following file: |
< | < | ||
[root@redhat9 tmp]# vi expand | [root@redhat9 tmp]# vi expand | ||
+ | |||
[root@redhat9 tmp]# cat expand | [root@redhat9 tmp]# cat expand | ||
un deux trois quatre cinq | un deux trois quatre cinq | ||
Ligne 2388: | Ligne 2396: | ||
un deux trois quatre cinq | un deux trois quatre cinq | ||
un deux trois quatre cinq | un deux trois quatre cinq | ||
- | </code>> | + | </ |
- | Utilisez les option | + | Now use the **-vet** |
< | < | ||
Ligne 2407: | Ligne 2415: | ||
<WRAP center round important 60%> | <WRAP center round important 60%> | ||
- | **Important** : Comme vous pouvez constater, les tabulations | + | **Important** : As you can see the tabulations |
</ | </ | ||
- | Utilisez maintenant la commande | + | Now use the **expand** |
< | < | ||
Ligne 2416: | Ligne 2424: | ||
</ | </ | ||
- | Visualisez le fichier avec la commande | + | View the resulting **expand1** file with the **cat** command and the **-vet** |
< | < | ||
Ligne 2433: | Ligne 2441: | ||
<WRAP center round important 60%> | <WRAP center round important 60%> | ||
- | **Important** : Comme vous pouvez constater, les tabulations | + | **Important** : As you can see, the tabulations |
</ | </ | ||
- | ==Options de la commande== | + | ==Command Line Switches== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
- | ===7.2 - La Commande | + | ===7.2 - The unexpand |
- | La commande | + | The **unexpand** |
- | Utilisez la commande | + | Now use the **unexpand** |
< | < | ||
Ligne 2477: | Ligne 2485: | ||
<WRAP center round important 60%> | <WRAP center round important 60%> | ||
- | **Important** : Notez que les espaces ont été remplacés par des tabulations. | + | **Important** : Note that the spaces have been replaced by tabulations. |
</ | </ | ||
- | ==Options de la commande== | + | ==Command Line Switches== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
- | ===7.3 - La Commande | + | ===7.3 - The cut Command=== |
- | + | ||
- | Chaque ligne est divisée en colonnes. Dans une ligne le premier caractère est dans la colonne numéro **un**, le deuxième dans la colonne deux et ainsi de suite. Dans une ligne il peut y avoir des champs séparés par des tabulations. | + | |
- | La commande **cut** permet de sélectionner des colonnes et des champs dans un fichier. La commande permet aussi d' | + | The cut command splits each line of a file into columns starting with column 1. Each column contains one character. The command can also be used to split lines into fields where the default seperator is a tablulation. The default seperator can be changed by using the **-d** |
- | Par exemple, pour sélectionner les 7 premières colonnes du fichier | + | Select the first 7 columns of the **/ |
< | < | ||
Ligne 2535: | Ligne 2541: | ||
</ | </ | ||
- | Pour sélectionner les colonnes | + | In order to select columns |
< | < | ||
Ligne 2578: | Ligne 2584: | ||
</ | </ | ||
- | Pour sélectionner les champs 2, 4 et 6 du fichier, il convient d' | + | In order to select the 2nd, 4th and 6th column, use the following command: |
< | < | ||
Ligne 2621: | Ligne 2627: | ||
</ | </ | ||
- | ==Options de la commande== | + | ==Command Line Switches== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
- | ===7.4 - La Commande | + | ===7.4 - The uniq Command=== |
- | La commande suivante permet d' | + | The following command is used to extract the Primary Group GIDs from the **/etc/passwd** file: |
< | < | ||
Ligne 2669: | Ligne 2675: | ||
<WRAP center round important 60%> | <WRAP center round important 60%> | ||
- | **Important** : Notez l' | + | **Important**: |
</ | </ | ||
- | ==Options de la commande== | + | ==Command Line Switches== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
- | ===7.5 - La Commande | + | ===7.5 - The tr Command=== |
- | La commande | + | The **tr** |
< | < | ||
Ligne 2723: | Ligne 2729: | ||
</ | </ | ||
- | ==Options de la commande== | + | ==Command Line Switches== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
- | ===7.6 - La Commande | + | ===7.6 - The paste Command=== |
- | La commande | + | The **paste** |
< | < | ||
Ligne 2774: | Ligne 2780: | ||
</ | </ | ||
- | + | ==Command Line Switches== | |
- | ==Options de la commande== | + | |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
- | ===7.7 - La Commande | + | ===7.7 - The split Command=== |
- | La commande **split** est utilisée pour découper de grands fichiers en petit morceaux d'une taille fixe ou d'un nombre de lignes fixe. | + | The split command is used to divide a large file into smaller segments. Create an empty 250 MB file as follows: |
- | + | ||
- | Créez d' | + | |
< | < | ||
Ligne 2794: | Ligne 2797: | ||
</ | </ | ||
- | Utilisez maintenant la commande **split** pour diviser ce fichier en morceaux de 50 Mo : | + | Now use the split command to divide the file into 5 smaller files each of 50: |
< | < | ||
[root@redhat9 tmp]# split -b 50m /file filepart | [root@redhat9 tmp]# split -b 50m /file filepart | ||
+ | |||
[root@redhat9 tmp]# ls -l | grep filepart | [root@redhat9 tmp]# ls -l | grep filepart | ||
-rw-r--r--. 1 root root 52428800 Sep 25 16:17 filepartaa | -rw-r--r--. 1 root root 52428800 Sep 25 16:17 filepartaa | ||
Ligne 2807: | Ligne 2811: | ||
<WRAP center round important 60%> | <WRAP center round important 60%> | ||
- | **Important** : Notez que cinq morceaux ont été créés dans le répertoire courant. Si aucune taille n'est spécifiée, | + | **Important**: |
</ | </ | ||
- | Reconstruisez simplement le fichier avec la commande | + | You can re-construct the original file by using the **cat** command: |
< | < | ||
Ligne 2820: | Ligne 2824: | ||
</ | </ | ||
- | ==Options de la commande== | + | ==Command Line Switches== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
- | ===7.8 - La Commande | + | ===7.8 - The diff Command=== |
- | La commande **diff** indique les modifications à apporter à deux fichiers pour que ceux-ci soient identique. | + | The diff command compares two fles and indicates what changes need to be made to the first file in order that it be identical to the second file. |
- | Pour commencer, copiez le fichier | + | Copy the **/ |
< | < | ||
Ligne 2836: | Ligne 2840: | ||
</ | </ | ||
- | Modifiez ensuite le fichier la ligne **trainee** du fichier | + | Edit the ***/ |
< | < | ||
Ligne 2844: | Ligne 2848: | ||
</ | </ | ||
- | Supprimez la ligne **tcpdump** | + | Delete the **tcpdump** |
< | < | ||
Ligne 2851: | Ligne 2855: | ||
</ | </ | ||
- | Comparez maintenant les deux fichiers | + | Now compare the two files: |
< | < | ||
Ligne 2864: | Ligne 2868: | ||
</ | </ | ||
- | Dans cette sortie on constate le caractère | + | In this output you will notice the **< |
- | Le message | + | The output |
- | Le message | + | The output |
- | ==Options de la commande== | + | ==Command Line Switches== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
- | ===7.9 - La Commande | + | ===7.9 - The cmp Command=== |
- | La commande | + | The **cmp** |
< | < | ||
Ligne 2885: | Ligne 2889: | ||
</ | </ | ||
- | L' | + | The **-l** |
< | < | ||
Ligne 2916: | Ligne 2920: | ||
</ | </ | ||
- | La première colonne représente le numéro de caractère, la deuxième la valeur octale | + | The first column represents the character **number**, the second column represents the **ASCII octal value** of the character in the **/ |
- | ==Options de la commande== | + | ==Command Line Switches== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
- | ===7.10 - La commande | + | ===7.10 - The patch Command=== |
- | La commande **patch** est utilisée pour appliquer des modifications à un fichier à partir d'un fichier patch qui contient les différences entre le contenu de l' | + | La commande **patch** est utilisée pour appliquer des modifications à un fichier à partir d'un fichier patch qui contient les The **patch** command is used to apply modifications contained within a patch file to an older version |
- | La commande | + | The **patch** command is not installed by default in RHEL 9: |
< | < | ||
Ligne 2934: | Ligne 2938: | ||
</ | </ | ||
- | Rappelez-vous maintenant des modifications apportées aux fichiers | + | If you recall, you made some changes to the / |
< | < | ||
Ligne 2952: | Ligne 2956: | ||
£ | £ | ||
# End comment | # End comment | ||
+ | |||
[root@redhat9 tmp]# cat / | [root@redhat9 tmp]# cat / | ||
fenestrOS | fenestrOS | ||
Ligne 2962: | Ligne 2967: | ||
</ | </ | ||
- | Afin de créer un fichier de patch, il convient d' | + | Now create a patch file containing the modifications that need to be applied to / |
< | < | ||
Ligne 2968: | Ligne 2973: | ||
</ | </ | ||
- | L' | + | A look at the patch file shows the chnages that need to be made to the **greptest** |
< | < | ||
Ligne 2991: | Ligne 2996: | ||
</ | </ | ||
- | Procédez maintenant à l' | + | Now apply the patch file: |
< | < | ||
Ligne 2998: | Ligne 3003: | ||
</ | </ | ||
- | Contrôlez maintenant le contenu du fichier | + | Finally, check the contents of the patched |
< | < | ||
Ligne 3011: | Ligne 3016: | ||
</ | </ | ||
- | ==Options de la commande== | + | ==Command Line Switches== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
- | ===7.11 - La commande | + | ===7.11 - The strings |
- | La commande | + | The **strings** |
- | Sous Linux et Unix, le format d'un fichier objet est le format **ELF**, (//Executable and Linkable Format//). Ce format | + | The format |
- | * les exécutables, | + | * executables, |
- | * les bibliothèques partagés, | + | * shared libraries, |
- | * les core dumps. | + | * core dumps. |
- | Sans option, la commande **strings** trouve toutes les chaînes d'une longueur de 4 caractères ou plus suivies par un caractère non-imprimable | + | Used as is, the command extracts all strings |
< | < | ||
Ligne 3057: | Ligne 3062: | ||
</ | </ | ||
- | L' | + | Print the offset within the file before each string: |
< | < | ||
Ligne 3087: | Ligne 3092: | ||
</ | </ | ||
- | L' | + | The **-t** |
- | ^ Argument ^ Système de Numérotation | + | ^ Argument ^ Numbering System |
- | | d | Décimal | + | | d | Decimal |
| o | Octal | | | o | Octal | | ||
- | | x | Héxadécimal | + | | x | Hexadecimal |
- | L' | + | The **-n** |
< | < | ||
Ligne 3124: | Ligne 3129: | ||
</ | </ | ||
- | Dans le cas de l' | + | The **-f** |
< | < | ||
Ligne 3221: | Ligne 3226: | ||
</ | </ | ||
- | <WRAP center round important 60%> | + | ==Command Line Switches== |
- | **Important** : Notez que l' | + | |
- | </ | + | |
- | + | ||
- | ==Options de la commande== | + | |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
- | ===7.12 - La commande | + | ===7.12 - The comm Command=== |
- | + | ||
- | La commande **comm** est utilisée pour comparer deux fichiers texte. La sortie de la commande sépare les lignes en trois catégories : | + | |
- | + | ||
- | * Les lignes présentes seulement dans le premier fichier, | + | |
- | * Les lignes présentes seulement dans le deuxième fichier, | + | |
- | * Les lignes présentes dans la deux fichiers. | + | |
- | Utilisez la commande **comm** pour comparer les fichiers **/ | + | This command compares two text files and prints the differences to standard output: |
< | < | ||
Ligne 3294: | Ligne 3289: | ||
</ | </ | ||
- | Pour afficher uniquement les lignes présentes dans les deux fichiers, il convient d' | + | <WRAP center round important 60%> |
+ | **Important**: The lines to the left are those that only appear in the first file. The lines on the right are those that exist in both files. The lines in the middle are those that only exist in the second file. | ||
+ | </ | ||
+ | |||
+ | If you only want to see the lines common to both files, use the following command: | ||
< | < | ||
Ligne 3326: | Ligne 3325: | ||
comm: file 1 is not in sorted order | comm: file 1 is not in sorted order | ||
</ | </ | ||
- | + | ==Command Line Switches== | |
- | ==Options de la commande== | + | |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
- | ===7.13 - La commande | + | ===7.13 - The head Command=== |
- | La commande | + | The **head** |
< | < | ||
Ligne 3351: | Ligne 3349: | ||
</ | </ | ||
- | Avec l' | + | You can change the default value of x by using the **-n** |
< | < | ||
Ligne 3372: | Ligne 3370: | ||
</ | </ | ||
- | La commande **head** peut également être utilisée pour afficher les premiers | + | The command can also be used to display the first **y** bytes of a file by using the **-c** |
< | < | ||
Ligne 3383: | Ligne 3381: | ||
</ | </ | ||
- | Dans le cas où le **y** est négatif, la commande **head** | + | If the value of **y** is negative, head displays all bytes in the file **except** the last y bytes: |
< | < | ||
Ligne 3423: | Ligne 3421: | ||
</ | </ | ||
- | Les valeurs **x** et **y** acceptent des multiplicateurs | + | Both x and y can accept multipliers: |
< | < | ||
Ligne 3457: | Ligne 3455: | ||
</ | </ | ||
- | Les multiplicateurs les plus utilisés sont : | + | The common multipliers are: |
- | ^ Multiplicateur | + | ^ Multiplier |
| b | 512 | | | b | 512 | | ||
| KB | 1000 | | | KB | 1000 | | ||
Ligne 3468: | Ligne 3466: | ||
| G | 1024*1024*1024 | | | G | 1024*1024*1024 | | ||
- | ==Options de la commande== | + | ==Command Line Switches== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
- | ===7.14 - La commande | + | ===7.14 - The tail Command=== |
- | La commande | + | The **tail** |
< | < | ||
Ligne 3492: | Ligne 3490: | ||
</ | </ | ||
- | Avec l' | + | You can change the default value of x by using the **-n** |
< | < | ||
Ligne 3513: | Ligne 3511: | ||
</ | </ | ||
- | La commande **tail** peut également être utilisée pour afficher les derniers | + | The command can also be used to display the last **y** bytes of a file by using the **-c** |
< | < | ||
Ligne 3522: | Ligne 3520: | ||
</ | </ | ||
- | Dans le cas où le **y** est positif, la commande **tail** affiche tous les octets du fichier à partir de la position de **y**ième octet : | + | If the value of **y** is positive, tail displays all bytes in the file after the yth byte: |
< | < | ||
Ligne 3560: | Ligne 3558: | ||
</ | </ | ||
- | Les valeurs **x** et **y** acceptent des multiplicateurs | + | Both x and y can accept multipliers: |
< | < | ||
Ligne 3586: | Ligne 3584: | ||
</ | </ | ||
- | Les multiplicateurs les plus utilisés sont : | + | The common multipliers are: |
- | ^ Multiplicateur | + | ^ Multiplier |
| b | 512 | | | b | 512 | | ||
| KB | 1000 | | | KB | 1000 | | ||
Ligne 3597: | Ligne 3595: | ||
| G | 1024*1024*1024 | | | G | 1024*1024*1024 | | ||
- | Une option intéressante pour la surveillance des fichiers de journalisation est **-f**. | + | A useful switch to use with the tail command is **-f**. |
< | < | ||
Ligne 3614: | Ligne 3612: | ||
</ | </ | ||
- | ==Options de la commande== | + | ==Command Line Switches== |
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | **A faire** : Utilisez l' | + | **To do** : Use the **--help** |
</ | </ | ||
- | ====LAB #8 - Utiliser les commandes ifconfig, | + | ====LAB #8 - Use the grep, tr and cut to extract your IPv4 address from the output of ifconfig==== |
< | < | ||
Ligne 3648: | Ligne 3646: | ||
<WRAP center round important 60%> | <WRAP center round important 60%> | ||
- | **Important** : Notez l' | + | **Important** : Note the use of the **-s** switch with the **tr** command. This switch replaces a string of x identical characters with a single character. |
</ | </ | ||
- | ====LAB #9 - Utiliser les commandes ip, grep, awk et sed pour isoler l' | + | ====LAB #9 - Use the grep, awk and sed to extract your IPv4 address from the output of ip==== |
< | < |