Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of linux Command

2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you the "sample analysis of linux commands", which is easy to understand and clear. I hope it can help you solve your doubts. Let the editor lead you to study and learn the article "sample analysis of linux commands".

Overview: users use shell to interact with the kernel. There are many commands in Linux, and different commands have different functions. Multiple commands can be combined to complete a large function. There are so many commands that we can't remember the usage of each command.

Therefore, we must have a way to quickly know how a command is used and what it does. Therefore, almost all commands provide a help manual that tells the user of the command how to use the command, the role of the command, and so on. The help manual page is so long that we can't read the help manual from beginning to end in order to use a command, so we need a way to quickly understand (purposefully read) the help manual of the command. How is it realized? In fact, it is the core (kernel computing system) that manages the entire computing hardware. Usually, users (user) communicate with the core through shell, so that the core can achieve what we want to achieve.

Shell is an application that reads commands typed by the user and converts it into a format that is easier for the Linux system to understand. It also includes some basic program structures that allow users to make options, loops, and set values

Stored in variables.

First, understand the basic format of the command

Shell executor:

Shell is responsible for executing the program requested by the terminal.

Each time the user types a line of information into the shell command prompt [root@Node1 ~] #, shell will decide what to do after the analysis. Every line of information involved in shell follows the same basic format. Such as:

Command options parameters command parameters (1) command parameters (2)

Commands generally provide help documentation, and only by understanding the meaning of the command format can we quickly learn the use of new commands. At least when you type a command at a command line prompt, you will not make a mistake.

First field: command (command) executable file

Second field: options for commands, options for some commands with parameters, and options for some commands without arguments

Brackets [] are selectable, and you can choose whether or not to omit the command when typing the command.

The vertical bar "|" indicates that either of the left and right sides is used as a parameter for the command option.

Ellipsis "." Indicates that there can be multiple options for the command, but when writing, follow the following format.

The options are as follows:

1. Long option, using-- options format. The general option name is complete. If a command has more than one long option, it cannot be merged.

2, short options, using the-options format, usually the shorthand format of the long option name. If there are multiple short options for a command, it can be merged.

The options-b and-- escape of the ls command have the same effect.

[root@Node1] # ls-b / root/

Anaconda-ks.cfg install.log install.log.syslog

[root@Node1] # ls-- escape / root/

Anaconda-ks.cfg install.log install.log.syslog

Note: long options cannot be combined. At the command line prompt, the commands typed should be written separately when multiple long options are used.

[root@Node1] # ls-- allblock-size=1 / etc/

Ls: unrecognized option'--allblock-size=1'

[root@Node1] # ls-- all-- block-size=4 / root/

. .bash _ history .bashrc install.log.syslog .tcshrc

.. .bash _ logout .cshrc .lesshst .viminfo

Anaconda-ks.cfg .bash _ profile install.log .ssh

Third field: command parameters

Multiple command parameters need to be separated by spaces.

When the user types the command in the format described above and presses the [Enter] key, shell parses and executes the command. ([Enter] is a character in Linux) shell will first determine the type of command, and if it is an internal command, it will be executed directly, otherwise, shell will search the disk according to the value of the $PATH variable and search for the command typed by the user.

1. If a command typed by the user is found and an interrupt occurs, the kernel (kernel) is responsible for loading the command file from disk to memory.

And begin to execute the command. At this point, the command is represented as a process.

2. If shell cannot find the command on disk according to the value of the $PATH variable, it will report an error.

[root@Node1 ~] # tree / etc

-bash: tree: command not found

Description:

If the location of the command is not in $PATH and the command does not exist, it will be reported as "command not found"

If the location of the command we typed is not in the shell search $PATH path, we can use the full path to describe the command, or set the

The path where the command is located is appended to the $PATH variable.

1. Use full path description file

[root@Node1 etc] # / usr/bin/tree / etc

2. Add the path of the command to the $PATH variable.

1 [root@Node1 ~] # vim / etc/profile

Add a line $PATH=/path2/path3/:/path3/path4 to the profile file

For example, when compiling and installing the MySQL database, the path of the tool provided by MySQL is set to the default search path of shell.

($PATH) In this way, using some commands provided by MySQL, when operating and maintaining the MySQL server

There is no need to enter the full path of the command. This is more convenient. Add a line to the profile file

$PATH=/usr/local/mysql/bin but the path just added to $PATH is not known to shell.

We need to notify shell and reread the profile file by:

[root@Node1 etc] #. Profile

Second, how do we know how to use a command?

In general, commands provide help documentation, through which we can see how a command is used. Our commands are divided into: shell built-in commands and external commands.

Depending on the type of command, the way to get its help documentation is also different. So, first of all, we have to judge the type of command?

To determine the command type, use [type]

[root@Node1 etc] # type cd

Cd is a shell builtin

Knowing that the [cd] command is a shell built-in command, we can use the following methods to see how to use the command

[root@Node1 etc] # help cd

Cd: cd [- L |-P] [dir]

Change the shell working directory.

Change the current directory to DIR. The default DIR is the value of the

HOME shell variable.

.

[root@Node1 etc] # type ls

Ls is aliased to `ls-- color=auto'

The ls command is an external command. We use the [command-- help] or [man] commands to view the command help documentation. Man means "man" in Chinese, roaming in the Linux world, ask "man" if you don't understand. So learn how to use man.

The help documentation for our non-kernel commands is stored in, / usr/share.

How does the [man] command work?

Man will follow the path defined by MANPATH in its configuration file / etc/man.config to search the help documentation for the command, when I

When we use [man] to view command's help documents, if command's help documents are not in the search path of the man program

Man cannot find the help documentation for command. So, when we compile and install the source program, if we install the

If the directory of the program's help documentation is not under the default search path of [man], you need to add the path of the program's help document to [man]

In the index path of the You can add the path of the program's help documentation to the MANPATH instruction by compiling / etc/man.config

It is fine, for example, add the path of the help document of MySQL to the search path of [man]

[root@node2 ~] # vim / etc/man.config

# MANBIN / usr/local/bin/man

#

# Every automatically generated MANPATH includes these fields

#

MANPATH / usr/man

MANPATH / usr/share/man

MANPATH / usr/local/man

MANPATH / usr/local/share/man

MANPATH / usr/X11R6/man

MANPATH / usr/local/mysql/man/

Our help documents are divided into chapters, and different chapters mean different things. By understanding the meaning of the different sections of the help document, we can use the [man] command to quickly locate what we need.

The contents of the view.

1. What are the chapters of the view command? Use [whatis] to retrieve the whatis databases database. The help documentation of the program we just installed will not be recorded in the database, and the Linux system uses [makewhatis] to generate the database. The system makes the action of generating database into a periodic task of the system. "04:22 on Sunday every week" performs the task of generating whatis data once. So the program we just installed can't find out how many chapters there are in the command using [whatis command]. If we need to check it, we can manually execute the [makewhatis] command to generate whatis databases.

[root@node2 ~] # whatis shutdown

Shutdown (2)-shutdown part of a full-duplex connection

Shutdown (3p)-shutdown socket send and receive operations

Shutdown (8)-bring the system down

2. The meaning expressed in the chapter is as follows

Man1 user command

Man2 system call

Man3 library call

Man4 device file

Man5 profile

Man6 games

Man7 Miscellaneous

Man8 management command

2. Use [man N] to enable users to view the contents of the sections of help documents at will.

[root@node2 ~] # man 8 shutdown

3. Use [help command] to view the use of command, which is not as detailed as man.

[root@node2] # shutdown-- help

Shutdown: invalid option

Usage: shutdown [- akrhHPfnc] [- t secs] time [warning message]

-a: use / etc/shutdown.allow

-k: don't really shutdown, only warn.

-r: reboot after shutdown.

-h: halt after shutdown.

-P: halt action is to turn off power.

-H: halt action is to just halt.

-f: do a 'fast' reboot (skip fsck).

-F: Force fsck on reboot.

N: do not go through "init" but go down real fast.

The help documentation for an application is usually made up of different paragraphs. Each paragraph describes the different content of the application. By understanding the meaning of the paragraphs in the help document, we can quickly find what we want to read.

The passage of the manual:

1. NAME command name

2. Detailed description of DESCRIPTION command function

3. OPTIONS all options

4. FILES configuration files related to the current command

5. EXAMPLES usage example

6. SYNOPSIS uses format

7. Other manuals that SEE ALSO can refer to

Description:

If we want to quickly find out how command works, we can check out the EXAMPLES section of the help manual. The command's help manual consists of many characters, so how do we locate the EXAMPLES characters?

When we use [man] to open the help page of the view command, we can use string search.

1, enter "/ keywork" from the beginning of the document to the end of the search, search to the specified character will be highlighted.

2, enter "? keywork" from the end of the document to the first search, search to the specified character will be highlighted.

When we search for characters that appear in multiple places in the document, we can press some "keys" to quickly display the next searched character.

1. N key: contrary to the search command, displays the next keyword found

2. N key: same as the search command, showing the next keyword found

The above is all the contents of the article "sample Analysis of linux commands". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report