Home >System Tutorial >LINUX >Optimize the use of man to improve efficiency and speed

Optimize the use of man to improve efficiency and speed

王林
王林forward
2024-01-06 19:26:251071browse
Introduction We usually use Google to query command instructions in Linux, but there is actually a better way: that is to query the detailed and complete instructions for using the command through the man help page that comes with Linux.
The

man page itself is older than Linux, dating back to the early days of Unix. From this Wikipedia, we can know that Dennis Ritchie and Ken Thompson wrote the first man help page in 1971. The calculators of that era still used computers like ovens, and personal computers had not yet been born. The man help page also has its own set of well-designed syntax. Like Unix and Linux, the man help page is not static. It is constantly evolving and updating just like the Linux kernel.

Man help pages are divided into different types of content by numerical identifiers:

  1. General user commands
  2. System call command
  3. Library Functions
  4. Special files and drivers
  5. file format
  6. Games and Screensavers
  7. Miscellaneous
  8. System Management Commands and Daemons

Despite this, users generally do not need to know which type the command they want to query belongs to.

The way these files are formatted seems a bit odd to many users today. Because they were initially printed using trooff via a PostScript printer, formatting information for headers and layout was included. In Linux, a method called groff is used instead.

In my Fedora system, files related to man help pages are stored in subdirectories under /usr/share/man (for example, man1 stores the first part of the command), and there are further subdirectories for storing man help. page translation.

If you look for the man help page of the man command in Shell, you will see the man.1.gz file compressed by the gzip tool. To query the man help page, you need to enter a command similar to the following:

man man

This example will display the man help page for the man command. This will first decompress the man help page file, then interpret the formatting instructions and display the results with less, so the navigation operation is the same as in less.

All man help pages should display these subsections: Name, Synopsis, Description, Examples, See, Also. Some also add additional subsections, such as Options, Exit, Status, Environment, Bugs, Files, Author, Reporting, Bugs, History, Copyright.

Details a man help page

In order to introduce a typical man help page in more detail, let’s use the help page of the ls command to analyze it. Under the Name section, we can see the following content:

ls - list directory contents

It will briefly tell me what the ls command does.

Under the Synopsis segment, we can see the following content:

ls [OPTION]... [FILE]…

Any element enclosed in square brackets is optional. You can just enter the ls command without any parameters. The ellipsis after the parameter means that you can add as many mutually compatible parameters as you want, as well as as many file names. For the [FILE] parameter, you can specify a specific directory name, or you can use the wildcard *, such as this example, which will display the .txt files in the Documents folder:

ls Documents/*.txt

Under the Description section, we can see more detailed information about this command, as well as a detailed list of the functions of each parameter of this command. For example, the first option of the ls command -a parameter, it The function is to display all files including hidden files/directories:

-a, --all

If we want to use these parameters, either use their aliases, such as -a, or use their full names, such as --all (two dashes). However, not all parameters have full names and aliases (for example, --author only has one), and the two names are not always related to each other (-F and --classify). When you want to use multiple parameters, either separate them with spaces or share a hyphen -, and enter the parameters you need continuously after the hyphen (do not add spaces). For example, the following two equivalent examples:

ls -a -d -l
ls -adl

However, there are some exceptions to the tar command. Due to some historical reasons, there is no need to add the hyphen - when the parameter uses an alias, so the following two commands are legal:

tar -cvf filearchive.tar thisdirectory/
tar cvf filearchive.tar thisdirectory/

ls The Description section is followed by Author, Reporting Bugs, Copyright, See Also and other sections.

The See Also section will provide some related man help pages, you can take a look if you have nothing to do. After all, there are many other types of man pages besides commands.

Some commands are not system commands, but are unique to Bash, such as alias and cd. These Bash-specific commands can be viewed in the BASH_BUILTINS man page. Their descriptions are more concise than the above, but the content is similar.

In fact, you can get a lot of useful information through the man help page, especially when you want to use a command that you haven't used for a long time and need to review the function of this command. In this case, the much-criticized simplicity of the man page may actually be better for you.


The above is the detailed content of Optimize the use of man to improve efficiency and speed. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:linuxprobe.com. If there is any infringement, please contact admin@php.cn delete