Linux comes with hundreds of commands, each of them with lots of options. It’s impossible, even for 1
an experienced Linux administrator to remember all the all the commands and their options. 2
Fortunately, Linux comes with its own help 3
built-in system. In this lecture will be talking about man pages. Man is short for a manual and a man 4
page is simply the documentation of a program or command. 5
You can use the man command to read the documentation of a specific command. 6
To open the man page of a command you type in the terminal: man and the command’s name. Let's open 7
the man page of the ls command. I'm writing, man ls. 8
By default, man uses a program called "less" to display the output. While you are in the man page, 9
you can get additional help by typing the letter h. 10
I've just typed h. 11
You see this title: summary of less commands. 12
This means that the man command used the less command to display the help. For a beginner it could sound 13
weird, but there's a command called less used to display the contents of the text files. It's a viewer 14
or a pager; to get out of this screen 15
you press q and to exit or to get out of the man program, you press q, which comes from quit 16
again. 17
Let's open the man page of ls again and see what is its main structure. 18
You'll find the same structure for all man pages. 19
The first line contains the name of the command you are reading about, along with a very short description. 20
Then comes the synopsis of the command, which provides a formal description of how to run it. 21
In this example we run it : ls some options and some files as arguments. 22
In a man page everything that appears directly before 3-dots, which are also called ellipsis, 23
can be repeated. 24
So it can repeat different options and also file names. This means that you can specify more than one 25
option or file. Options and arguments are put between square brackets to indicate that they can be left 26
out. 27
They are not mandatory. 28
This is the case of ls. 29
We can run it both with or without options and arguments. 30
Other conventions used in man pages are: when you see bold text, you are supposed to type in exactly 31
as seen. 32
But when you see an underline or italic text, you need to substitute it with something appropriate. 33
Here 34
we don't write size s iz e, but we have to specify the size, the actual size. 35
After the synopsis, a longer description of the command is given together with all its available options. 36
When you see an option in short format, a comma and an option in long format, it means that you can 37
use any form you wish. 38
Note that some man pages contain an extra section called Options, where the options are explained. 39
Take a look at the man page of the df command. 40
This is the options section. 41
At the end of the man page, there are the author, the copyright and see also sections. Let's go 42
ahead and talk about the navigation within our man page. 43
Let's see the most important navigation keys. 44
Use the arrow keys to move a line up or down. 45
Up and down! 46
To forward one window press on control and F or on the space key. I'm forwarding one window. 47
I'm at the end and if you want to move backwards a screen or a window, you press control and B. 48
I'm moving backwards. 49
And to go to the very beginning of the man page type lower case G, I'm at the beginning; 50
And to go to the very end type upper case G, I'm at the end. 51
Sometimes you want to search in the current man page for a specific option; let's say we are in the man 52
page of ls and we want to find the matches for “sort” within that manual page. 53
First, I'm going at the beginning, so I am pressing g. 54
What I'll do now is write a backslash and the string I want to search for: sort and I'm hitting enter 55
Any matches in the current man page will be highlighted. 56
You can then navigate between matches with n 57
like this or shift+ n or uppercase N. N we'll take you to the next match and shift n or uppercase N 58
will go to the prior match. 59
So backwards! When you search using a forward slash the searched term it is searched forward. 60
But if you are, for example, at the end of the man page, so I'm pressing uppercase G to the end 61
and want to search backwards then you type a question mark and the search term. 62
Or -u 63
I was searching backwards for -u, and it found a match, which says that the option is used 64
not to sort file entries. 65
OK, those were the most important things about the man pages that 66
I think you should now; also note that there are two types of commands in Linux: commands that are executable 67
files on the disk and shell built in commands. 68
The last ones are built into the shell and most of the time they don't have a dedicated man page. 69
I'm quitting pressing g. To check if a command is an executable file or a shell built in use the 70
type commands . 71
So type f. 72
It's displaying the path to the command. 73
Or type apt! All these commands are executable files and have their own dedicated man pages, but 74
commands like cd, alias or umask are shell built-in and do not have a dedicated man page. 75
All these commands are shell built in. 76
To see the help of such a command instead of man used to help command and the command name, so help 77
cd 78
And you see its help. 79
So cd used to change the shell working directory. 80
Note that you can use the help command only for a shell built in commands and not for commands that are 81
executable files on the disk. 82
So help ls it's not working. 83
But another way to get some help is to write the name of the command and --help, this is 84
available for both shell builtin and executable files commands. 85
So rm --help or ls --help or cd --help and so on. 86
I'll introduce you a new command, which is ifconfig. 87
This is used to both display information about the network interfaces and configure them. 88
If you want to see the IP or Mac address of a network interface, you have ifconfig at your disposal. 89
ifconfig belongs to net-tools package; 90
if, when running ifconfig , it says command not found then you should first install the 91
net tools package. 92
Run as root on Ubuntu apt install net-tools so sudo 93
the command will run as root apt 94
install net tools. 95
Or on CentOS dnf install net-tools. 96
Sudo dnf install net-tools. 97
On CentOS is already installed; and a final trick I'd like to give you is how to search for a command, feature 98
keyword in all man pages. To do that, use man -k and the keyword you are searching for. 99
Let's say man- k ifconfig. 100
Or man -k uname 101
You can also pass a string enclosed in double quotes as argument: man -k "copy files". 102
It will search for the string copy files in all man pages; and it found 3 commands. 103
Note that man -k is similar to the apropos command 104
So apropos and the command ifconfig. 105
Or apropos uname 106
It's the same. 107
In these examples, it has searched for ifconfig, respectively, uname in all man pages and 108
has displayed the commands that contain references to the searched keyword. 109
Now if I want, I can check the man pages of those commands to dive deeper.