2.2 Using the Command Line to Get Help

2.2 Using the Command Line to Get Help

Weight: 2

Description: Running help commands and navigation of the various help systems.

Key Knowledge Areas:

  • Man pages

  • Info pages

The following is a partial list of the used files, terms and utilities:

  • man

  • info

  • /usr/share/doc/

  • locate

Linux commands are essential for working with the operating system, but some can be difficult to remember, especially for beginners. This lesson will teach you how to use helpful tools and documentation to find information about Linux commands, making it easier to use and understand them.

Ways to get help

Learning how to access help resources can enhance your problem-solving skills, benefiting your future learning and endeavors.

Man Pages
info
less
-h or --help

Built in

Less common

for viewing files

Doesn't always work

Informative

Newer than man

/usr/share/doc

man

The man command in Linux is used to display the manual pages for other commands and utilities. It provides detailed documentation about the usage, options, and functionality of commands, making it an essential tool for both beginners and experienced users. Each manual page includes sections such as NAME, SYNOPSIS, DESCRIPTION, OPTIONS, and EXAMPLES, which help users understand and effectively use the command.

The man command is essentially the Linux manual reader. When you type man followed by a command name, it retrieves and displays the manual page for that command, offering comprehensive details on how to use it, including all available options and flags. This command is crucial for learning about the tools and commands available in the Linux operating system.

The basic syntax of the "man" command is as follows:

Here,

"option" refers to additional flags that modify the behavior of the "man" command,

"command" is the Linux command or utility for which you want to access the manual.

Man Command Options

The "man" command itself has options that enhance its functionality:

Option

Description

man [command]

Display the manual page for the specified command.

-f, --whatis

Display a concise one-line description of the command.

-k, --apropos

Search for commands related to a given keyword.

-a, --all

Display all matching manual pages for the specified command.

Spacebar

Move forward one page in the manual.

Enter

Move forward one line in the manual.

B

Move backward one page in the manual.

Q

Quit the manual viewer.

Accessing Manual Pages

to access the manual page for a specific command, simply type:

For example , To view the manual for the "ls" command execute the following command:

This will display detailed information about the "ls" command, including its usage, options, and examples.

Once you've accessed a manual page, you can navigate through it using various commands. The common navigation keys include:

  • Spacebar: Move forward one page.

  • Enter: Move forward one line.

  • B: Move backward one page.

  • Q: Quit the manual viewer.

Sections in Manual Pages

Manual pages are organized into different sections, each serving a specific purpose. The primary sections include:

  • NAME: Provides the name and a brief description of the command.

  • SYNOPSIS: Describes the syntax of the command.

  • DESCRIPTION: Offers a detailed explanation of the command's functionality.

  • OPTIONS: Lists the available command-line options and their descriptions.

  • EXAMPLES: Provides practical examples demonstrating command usage.

  • SEE ALSO: Suggests related commands or resources.

info

info command reads documentation in the info format. It will give detailed information for a command when compared with the man page. The pages are made using the Texinfo tools which can link with other pages, create menus, and easy navigation.

syntax:

where,

  • 'OPTIONS': Modify the behavior of the command.

  • 'MENU-ITEM': Specify a particular section or node in the documentation to visit.

Key Options for the info command

The info command supports several options that enhance its functionality. Below are the most useful ones:

Option

Description

-a, --all

Use all matching manuals.

-k, --apropos=STRING

Look up STRING in all indices of all manuals.

-d, --directory=DIR

Add DIR to INFOPATH.

-f, --file=MANUAL

Specify the Info manual to visit.

-h, --help

Display help and exit.

-n, --node=NODENAME

Specify nodes in the first visited Info file.

-o, --output=FILE

Output selected nodes to FILE.

-O, --show-options, --usage

Go to the command-line options node.

-v, --variable VAR=VALUE

Assign VALUE to the Info variable VAR.

--version

Display version information and exit.

-w, --where, --location

Print the physical location of the Info file.

example:

output:

The /usr/share/doc directory

The /usr/share/doc directory is another excellent place to look for help in Linux. This directory has very intensive documentation; it doesn't just show you how to use a command; sometimes, it will even show the name and contact information of the authors who developed the command. Moreover, it may also include a TODO file that contains a list of unfinished tasks/features; contributors usually check the TODO files to help fix bugs and develop new features.

To demonstrate, let's go to the grep documentation directory:

How ever there are several ways to see the content of these files, let use less command.

less

The less command in Linux is used to view the contents of a file one page at a time without opening it in an editor, making it ideal for reading large files efficiently.

  • It allows you to scroll forward and backward through a file.

  • It does not load the entire file into memory, making it faster for large files.

  • You can search for specific text within the file using /pattern.

  • It provides navigation shortcuts (e.g., Space for next page, b for previous page, q to quit).

  • Commonly used to view log files, configuration files, or command outputs (cat filename | less or less filename)

Syntax:

  • Here, `filename` represents the name of the file we want to view using the `less` command.

  • The less command provides several options that modify its behavior.

Commonly Used Options in`less`command

Here are the most commonly used and practical options of the less command in Linux:

Options

Description

-E

Automatically exit when reaching the end of the file.

-f

Force non-regular files to be opened.

-F

Exit if the entire file can be displayed on the first screen.

-g

Highlight the string that was found by the last search command.

-G

Suppress highlighting of search matches.

-i

Ignore cases when searching.

-n

Suppress line numbers.

-p pattern

Start at the first occurrence of the specified pattern in the file.

-s

Squeeze consecutive blank lines into a single line.

-q

quit less

Command
Action

Down arrow, Enter, e, or j

Move forward one line.

Up arrow,y or k

Move backward one line.

Space bar or f

Move Forward one page.

b

Move Backward one page.

lets go back our example and see the content of grep command manusals:

output:

Cool! You can view the AUTHORS file to see the team of developers who contributed...

Use the --help Option

Many Linux commands support a --help option that provides a quick overview of the command's usage. This is often the fastest way to get basic information about a command.

Try using the --help option with the which command:

Type this command and press Enter. You should see a summary of the which command's options and usage:

command --help vs man command

locate

The locate command in Linux is a fast and efficient tool used to find files by their name. Unlike the find command, it searches through a pre-built database of file paths instead of scanning the entire filesystem, making searches much quicker.

  • Used to search and locate files or directories by name.

  • Works faster than the find command because it uses a pre-indexed database.

  • The database is updated using the updatedb command.

  • Newly created files do not appear until the database is refresh

Example : Search a File with Specific Name Using locate Command

It will search for myfile.txt

That's all

.

.

.


source: https://labex.io/tutorials/linux-get-help-on-linux-commands-18000 https://www.geeksforgeeks.org/linux-unix/man-command-in-linux-with-examples/ https://www.geeksforgeeks.org/linux-unix/info-command-in-linux-with-examples/

https://linuxize.com/post/less-command-in-linux/

https://subscription.packtpub.com/book/cloud-and-networking/9781800566002/5/ch05lvl1sec48/the-usr-share-doc-directory#:~:text=The%20%2Fusr%2Fshare%2Fdoc%20directory%20is%20another%20excellent%20place,authors%20who%20developed%20the%20command. https://www.geeksforgeeks.org/linux-unix/locate-command-in-linux-with-examples/

Last updated