0% found this document useful (0 votes)
8 views12 pages

CH 4

Uploaded by

Asmaa Yehia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views12 pages

CH 4

Uploaded by

Asmaa Yehia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Aya Magdy Youssef +201554481185 ayamagdy80888@gmail.

com

CH4: Get Help in Red Hat


Enterprise Linux
Table of Contents
1. Reading manual pages...........................................................................................................1
1.1 Reading manual pages....................................................................5
1.2 Example............................................................................................................................5
1.3 Reading manual pages getting..........................................................................................7
2. Searching in Linux: Commands and Examples.....................................................................9
2.1 which [command].............................................................................................................9
2.2 whereis [command]..........................................................................................................9
2.3 locate [name]....................................................................................................................9
2.4 find [path] -name [search_pattern].................................................................................10
2.4.1 find [path] -size [+100M].......................................................................................10
2.5 grep [search_pattern] [file_name]..................................................................................10
2.5.1 grep -r [search_pattern] [directory_name]..............................................................11
2.5.2 grep -l [search_pattern] [file_name].......................................................................11
2.5.3 grep -i [search_pattern] [file_name].......................................................................11
2.5.4 grep -v [search_pattern] [file_name]......................................................................11
2.5.5 grep -w [search_pattern] [file_name].....................................................................12
2.5.6 grep -A [number] [search_pattern] [file_name].....................................................12

Goal

Resolve problems by using local help systems.

Objectives

Find information in local Linux system manual pages.

1. Reading manual pages


Whenever you have a command installed on a Linux system, it usually comes with a
set of Manual Pages (man pages). These man pages serve as the complete
documentation for that command. They contain detailed information such as the
command's name, its syntax, a description, the available options, and sometimes even
examples of how to use the command.

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:

 Section 1 contains the manual pages for User Commands.


 Section 5 includes the manual pages for configuration files present on the
system.
 Section 8 has the manual pages for System Administration Commands.
 Occasionally, you might also use Section 4, which covers Special Files.

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.1 Reading manual pages

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]

1.3 Reading manual pages getting

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.

There’s also additional documentation available under /usr/share/doc, which often


contains more information than the manual pages. You can open these documents
using Firefox, and you can even open Firefox from the command line interface to
view this documentation.

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.

Additionally, there’s some extra documentation stored under the /usr/share/doc


directory on your system. This documentation often contains more detailed
information than what’s available in the man pages. You can open these documents
using Firefox, and you can even launch Firefox from the command line interface
(CLI) to view the documentation.

8|Page
Aya Magdy Youssef +201554481185 [email protected]

2. Searching in Linux: Commands and Examples


2.1 which [command]
Searches for the path of a command by checking the directories listed in the $PATH
environment variable.
Example:

This shows that the bash command is located in /bin.

2.2 whereis [command]


Finds the location of the source, binary, and manual page for a command.

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

2.3 locate [name]


Searches for all files and directories related to a specific name.
Example:

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

2.4 find [path] -name [search_pattern]


Finds files and directories that match a specified pattern in a specific path.

Example:

This command searches for all .txt files in the /home directory.

2.4.1 find [path] -size [+100M]


Finds files and directories larger than a specified size in a directory.

Example:
bash

find /var -size +100M


Output:
bash

/var/log/large_logfile
This command lists files in /var that are larger than 100 MB.

2.5 grep [search_pattern] [file_name]


Searches for a specific pattern in a file.
Example:
grep bash /etc/passwd
Output:
user:x:1000:1000::/home/user:/bin/bash
This searches for the word "bash" in the /etc/passwd file.

10 | P a g e
Aya Magdy Youssef +201554481185 [email protected]

2.5.1 grep -r [search_pattern] [directory_name]


Recursively searches for a pattern in all files within a directory.

Example:

This searches for "bash" in all files inside the /etc directory and its subdirectories.

2.5.2 grep -l [search_pattern] [file_name]


Displays only the file name if the pattern is found in the file.

Example
grep -l bash /etc/passwd
Output:
/etc/passwd

2.5.3 grep -i [search_pattern] [file_name]


Searches for a pattern, ignoring case sensitivity.

Example:
grep -i ROOT /etc/passwd
This finds all instances of "ROOT" or "root," regardless of case.

2.5.4 grep -v [search_pattern] [file_name]


Displays all lines except those that contain the pattern.

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]

2.5.5 grep -w [search_pattern] [file_name]


Searches for the exact word match in a file.

Example:

grep -w bash /etc/passwd


This finds lines where "bash" appears as a whole word, not as part of another word.

2.5.6 grep -A [number] [search_pattern] [file_name]


Displays the matched line and a specified number of lines after it.

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

You might also like