You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/books/admin_guide/03-commands.md
+39-16Lines changed: 39 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -270,7 +270,7 @@ The `clear` command clears the contents of the terminal screen. In fact, to be m
270
270
271
271
In a terminal, the display will be permanently hidden, whereas in a graphical interface, a scrollbar will allow you to go back in the history of the virtual terminal.
272
272
273
-
!!! tip
273
+
💡 **Tip:**
274
274
<kbd>CTRL</kbd> + <kbd>L</kbd> will have the same effect as the `clear` command
275
275
276
276
### `echo` command
@@ -312,7 +312,7 @@ $ date -d 20210517 +%j
312
312
313
313
In this last example, the `-d` option displays a given date. The `+%j` option formats this date to show only the day of the year.
314
314
315
-
!!! Warning
315
+
💡 **Warning:**
316
316
The format of a date can change depending on the value of the language defined in the environment variable `$LANG`.
317
317
318
318
The date display can follow the following formats:
@@ -497,7 +497,7 @@ $ ls -lia /home
497
497
|`25 oct. 08:10`| Last modified date. |
498
498
|`rockstar`| The name of the file (or directory). |
499
499
500
-
!!! Note
500
+
💡 **Note:**
501
501
**Aliases** are frequently positioned in common distributions.
502
502
503
503
This is the case of the alias `ll`:
@@ -604,7 +604,7 @@ $ mkdir /home/rockstar/work
604
604
The "rockstar" directory must exist to create the "work" directory.
605
605
Otherwise, the `-p` option should be used. The `-p` option creates the parent directories if they do not exist.
606
606
607
-
!!! Danger
607
+
💡 **Danger:**
608
608
It is not recommended to use Linux command names as directory or file names.
609
609
610
610
### `touch` command
@@ -627,7 +627,7 @@ $ touch /home/rockstar/myfile
627
627
628
628
Date format: `[AAAA]MMJJhhmm[ss]`
629
629
630
-
!!! Tip
630
+
💡 **Tip:**
631
631
The `touch` command is primarily used to create an empty file, but it can be useful for incremental or differential backups for example. Indeed, the only effect of executing a `touch` on a file will be to force it to be saved during the next backup.
The `rm` command itself does not ask for confirmation when deleting files. However, with a RedHat/Rocky distribution, `rm` does ask for confirmation of deletion because the `rm` command is an `alias` of the `rm -i` command. Don't be surprised if on another distribution, like Debian for example, you don't get a confirmation request.
669
669
670
670
Deleting a folder with the `rm` command, whether the folder is empty or not, will require the `-r` option to be added.
@@ -760,6 +760,7 @@ $ cp -r /home/rockstar /tmp
760
760
|`-f`| Do not ask for confirmation if overwriting the destination file. |
761
761
|`-p`| Keeps the owner, permissions and timestamp of the copied file. |
762
762
|`-r`| Copies a directory with its files and subdirectories. |
763
+
|`-s`| Creates a symbolik links rather than copying |
763
764
764
765
```bash
765
766
cp file1 /repexist/file2
@@ -1017,6 +1018,27 @@ $ sort -nr dns-client.txt
1017
1018
5.1.150.146
1018
1019
```
1019
1020
1021
+
* Sorting file by removing duplicates
1022
+
1023
+
The `sort`command knows how to remove the duplicates from the file output using `-u` as option.
1024
+
1025
+
Here is an example with the file `colours.txt`:
1026
+
1027
+
```
1028
+
Red
1029
+
Green
1030
+
Blue
1031
+
Red
1032
+
Pink
1033
+
```
1034
+
```
1035
+
$ sort -u colours.txt
1036
+
Blue
1037
+
Green
1038
+
Pink
1039
+
Red
1040
+
```
1041
+
1020
1042
* Sorting file by sizes
1021
1043
1022
1044
The `sort`command knows how to recognize file sizes, from commands like `ls` with the `-h` option.
The previous command searches forall filesin the `/tmp` directory named `*.txt` and deletes them.
1096
1118
1097
-
!!! Tip "Understand the `-exec` option"
1119
+
1120
+
💡 **Tip:**"Understand the `-exec` option"
1098
1121
In the example above, the `find`command will construct a string representing the command to be executed.
1099
1122
1100
1123
If the `find`command finds three files named `log1.txt`, `log2.txt`, and `log3.txt`, then the `find`command will construct the string by replacing in the string `rm -f {} \;` the braces with one of the results of the search, and do this as many times as there are results.
@@ -1107,7 +1130,7 @@ The previous command searches for all files in the `/tmp` directory named `*.txt
1107
1130
1108
1131
The `;` character is a special shell character that must be protected by a `\` to prevent it from being interpreted too early by the `find`command (and not in the `-exec`).
1109
1132
1110
-
!!!Tip
1133
+
💡 **Tip:**
1111
1134
`$ find /tmp -name *.txt -delete` does the same thing.
1112
1135
1113
1136
### `whereis` command
@@ -1160,7 +1183,7 @@ The `grep` command returns the complete line containing the string you are looki
1160
1183
$ grep -w "^root" /etc/passwd
1161
1184
```
1162
1185
1163
-
!!!Note
1186
+
💡 **Note:**
1164
1187
This command is very powerful and it is highly recommended to consult its manual. It has many derivatives.
1165
1188
1166
1189
It is possible to search fora stringin a file tree with the `-R` option.
Always surround words containing meta-characters with `"` to prevent them from being replaced by the names of files that meet the criteria.
1206
1229
1207
-
!!!Warning
1230
+
💡 **Warning:**
1208
1231
Do not confuse shell meta-characters with regular expression meta-characters. The `grep`command uses regular expression meta-characters.
1209
1232
1210
1233
## Redirects and pipes
@@ -1233,7 +1256,7 @@ It is possible to redirect the input stream from another file with the character
1233
1256
$ ftp -in serverftp << ftp-commands.txt
1234
1257
```
1235
1258
1236
-
!!!Note
1259
+
💡 **Note:**
1237
1260
Only commands that require keyboard input will be able to handle input redirection.
1238
1261
1239
1262
Input redirection can also be used to simulate user interactivity. The command will read the input stream until it encounters the defined keyword after the input redirection.
@@ -1260,7 +1283,7 @@ STOP
1260
1283
1261
1284
The shell exits the `ftp`command when it receives a line containing only the keyword.
1262
1285
1263
-
!!!Warning
1286
+
💡 **Warning:**
1264
1287
The ending keyword, here `END` or `STOP`, must be the only word on the line and must be at the beginning of the line.
1265
1288
1266
1289
The standard input redirection is rarely used because most commands accept a filename as an argument.
@@ -1414,7 +1437,7 @@ For permanent use, they must be created in the :
1414
1437
*`.bashrc` file in the user's login directory;
1415
1438
* `/etc/profile.d/alias.sh` file for all users.
1416
1439
1417
-
!!! Warning
1440
+
💡 **Warning:**
1418
1441
Special care must be taken when using aliases which can be potentially dangerous! For example, an alias set up without the administrator's knowledge :
0 commit comments