CH 4
CH 4
com
Goal
Objectives
1|Page
Aya Magdy Youssef +201554481185 [email protected]
The man pages provide all the information you might need. As a system administrator
working with Linux every day, you have to manage a large number of commands,
each with many options. It's difficult to memorize all the options for every command.
Therefore, system administrators often refer to the man pages for assistance.
These man pages are divided into different sections, with each section storing
manuals for specific types of commands or files. Typically, as a system administrator,
you'll interact with three or four of these sections the most:
These sections help you quickly find the information you need depending on the type
of command or file you are dealing with.
2|Page
Aya Magdy Youssef +201554481185 [email protected]
All the manual pages on the system are stored in the /usr/share/man directory.
To display the manual pages for any command, you use a command called man. You
simply type man followed by the name of the command you want to look up.
# man passwd
If you want to specify a particular section of the manual to search in, you can do that
by typing man, followed by the section number, and then the name of the file or
command.
# man 5 passwd
If you want to search within the manual pages for a specific pattern, you use the man
command with the -K option, followed by the pattern you want to search for.
3|Page
Aya Magdy Youssef +201554481185 [email protected]
# man -K print
There's also a command called which, which we’ve used before. This command helps
you find out where a particular command is stored on the system.
# which passwd
4|Page
Aya Magdy Youssef +201554481185 [email protected]
1.2 Example
Forward slash /
Shift + n -> if I in end “man” I must make shift + n to search from begin man to end
5|Page
Aya Magdy Youssef +201554481185 [email protected]
6|Page
Aya Magdy Youssef +201554481185 [email protected]
If you want to display where the manual pages for a particular file or command are
stored, you can use the whereis command.
If you just want a quick list of basic options and not the full documentation from the
manual, you can use the --help option. This gives you a brief overview of the most
common options.
When you navigate to the /usr/share/man directory, you’ll find all the manual pages
stored there.
If you can't find what you're looking for in the CLI manual pages or by using the --
help option, you can check online documentation. For example, Red Hat’s
documentation is available on their website.
For example:
# whereis passwd
passwd: /usr/bin/passwd /etc/passwd
/usr/share/man/man5/passwd.5.gz
/usr/share/man/man1/passwd.1ossl.gz /usr/share/man/man1/passwd.1.gz
# passwd --help
# cd /usr/share/man/
[root@MohamedAtef man]# ls
ca de hu ja man1 man2 man3p man4x man6 man7x man9 nl pt sk tr zh_TW
cs es id ko man1p man2x man3x man5 man6x man8 man9x overrides pt_BR
sr uk
da fr it man0p man1x man3 man4 man5x man7 man8x mann pl ru sv zh_CN
7|Page
Aya Magdy Youssef +201554481185 [email protected]
This shows how you can use whereis to locate the manual pages for a command, use
--help for quick options, and navigate through the directories where manual pages
are stored.
If you can’t find what you’re looking for in the manual pages available in the CLI, or
if the --help option doesn’t provide the information you need, you can refer to online
documentation. For instance, Red Hat’s documentation is available on their website.
8|Page
Aya Magdy Youssef +201554481185 [email protected]
Example:
This output indicates the binary and manual page for the ls command.
If you’re looking for a binary file, you can use the whereis command to locate it. This
command returns not only the location of the binary but also its source and man page if they
are available
9|Page
Aya Magdy Youssef +201554481185 [email protected]
This shows all files and directories with the name "passwd."
The locate command is not perfect, however. Sometimes the results of locate can be
overwhelming, giving you too much information. Also, locate uses a database that is usually
only updated once a day, so if you just created a file a few minutes or a few hours ago, it
might not appear in this list until the next day. It’s worth knowing the disadvantages of these
basic commands so you can better decide when best to use each one.
So, you must make
Sudo updatedb
Example:
This command searches for all .txt files in the /home directory.
Example:
bash
/var/log/large_logfile
This command lists files in /var that are larger than 100 MB.
10 | P a g e
Aya Magdy Youssef +201554481185 [email protected]
Example:
This searches for "bash" in all files inside the /etc directory and its subdirectories.
Example
grep -l bash /etc/passwd
Output:
/etc/passwd
Example:
grep -i ROOT /etc/passwd
This finds all instances of "ROOT" or "root," regardless of case.
Example:
grep -v aya /etc/passwd
This shows all lines in /etc/passwd that do not contain "aya."
11 | P a g e
Aya Magdy Youssef +201554481185 [email protected]
Example:
Example:
grep -A 2 root /etc/passwd
Output:
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
This shows the line with "root" and the two lines following it.
12 | P a g e