How to quickly learn linux commands

Source: Internet
Author: User

How to quickly learn linux commands

Overview: You can 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. Many Commands cannot be remembered.

Therefore, we must have a way to quickly know how a command is used. Therefore, almost all commands provide a help manual to tell the command user how to use the command, the role of the command, and so on. The help manual page is very long. It is impossible for us to read the help manual from start to end in order to use a command. At this time, we need a quick (purposeful) Help manual method. How is it implemented? The management of the entire computing hardware is actually the core (kernel computing requires a system). Generally, Users communicate with the core through shell, so that the core can achieve what we want to achieve.

Shell is an application that reads the commands you type and converts them to a more understandable format in Linux. It also includes some basic program structures, allowing users to make options, loops, and values

Stored in variables.

1. Understand the basic command format

Shell execution program:

Shell is responsible for executing the client request program.

Each time a user sends a shell command prompt [root @ Node1 ~] # "Type a line of information, and shell will decide what to do after analysis. Each line of shell information follows the same basic format. For example:

Command Option option parameter command parameter (1) command parameter (2)

Commands are generally provided with help documentation. Only by understanding the meaning of the command format can we quickly learn how to use new commands. At least when you type a command in the command line prompt, no error is written.

Field 1: command Executable File

Field 2: Command Options. Some Command Options include parameters, while some command options do not.

Brackets [] are optional. You can select whether to omit the command when you type the command.

The vertical line "|" indicates either of the left and right sides as a parameter of the Command Option.

The ellipsis "..." indicates that this command option can have multiple options, but the following format must be used for writing.

The options are as follows:

1. Long options, in the -- options format. The general option name is complete. If a command has multiple long options, it cannot be merged.

2. Short options are in the-options format, which is generally abbreviated as long option names. You can merge multiple short options of a command.

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

[Root @ Node1 ~] # Ls-B/root/anaconda-ks.cfginstall.loginstall.log.syslog [root @ Node1 ~] # Ls -- escape/root/anaconda-ks.cfginstall.loginstall.log.syslog

Note: Long options cannot be used in combination. In the command line prompt, you must separate the long options when using the commands you type.

[Root @ Node1 ~] # Ls -- allblock-size = 1/etc/ls: unrecognizedoption '-- allblock-size = 1' [root @ Node1 ~] # Ls -- all -- block-size = 4/root/.. bash_history.bashrcinstall.log.syslog.tcshrc... bash_logout.cshrc.lesshst.viminfoanaconda-ks.cfg.bash_profileinstall.log.ssh

Field 3: Command Parameters

Multiple command parameters must be separated by spaces.

After you type the command in the command line prompt according to the format described above, press the [Enter] key and shell will analyze and execute the command. (In Linux, the [Enter] is <CR> character representation.) shell will first determine the type of the command. If it is an internal command, it will be executed directly. Otherwise, shell searches for the disk based on the value of the $ PATH variable. The command is entered by the user.

1. If the user-typed command is found to cause interruptions, the kernel is responsible for loading the command file from the disk to the memory.

And start executing the command. The command is a process.

2. If shell cannot find this command in disk according to the value of $ PATH variable, an error is reported.

[Root @ Node1 ~] # Tree/etc-bash: tree: commandnotfound

Note:

If the command is not in $ PATH or does not exist, "command not found" is reported"

If the location of the command we typed is not in the $ PATH searched by shell, you can use the full PATH to describe the command or

Append the command PATH to the $ PATH variable.

1. Use the full path description file

[Root @ Node1etc] #/usr/bin/tree/etc

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

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

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

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

($ PATH ). In this way, some commands provided by MySQL are used to operate and maintain the MySQL server.

You do not need to enter the full path of the command. This is more convenient. Add a row to the profile file

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

We want to notify shell to re-read the profile file:

[Root @ Node1etc] #. profile

2. How do we know how to use a command?

Generally, commands provide help documents. We can use the help documents to view how to use a command. Our commands are divided into shell built-in commands and external commands.

Command types are different, and the methods for getting help documentation are also different. Therefore, we must first determine the type of a command?

Determine the command type, and use [type]

[Root @ Node1etc] # typecdcdisashellbuiltin

The [cd] command is a built-in shell command. You can use the following method to view how to use this command:

[Root @ Node1etc] # helpcdcd: cd [-L |-P] [dir] Changetheshellworkingdirectory. changethecurrentdirectorytoDIR. thedefaultDIRisthevalueoftheHOMEshellvariable ....... [root @ Node1etc] # typelslsisaliasedto 'ls -- color = auto'

The ls command is an external command. Run the command -- help or man command to view the command help document. Man Chinese meaning "man", in the Linux World Travel, don't understand ask "man ". Therefore, we must learn how to use man.

Our help documents for non-kernel commands are stored in/usr/share.

[Man] How does a command work?

Man will search for the help document of the command according to the path defined by MANPATH in its configuration file/etc/man. config.

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

Man cannot find the help document of command. Therefore, when compiling and installing the source program

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

. You can add the path of the help document of the program to the MANPATH command by compiling/etc/man. config.

You can, for example, add the path of MySQL help document to the search path of [man ].

[Root @ node2 ~] # Vim/etc/man. config # MANBIN/usr/local/bin/man # MANPATH/usr/share/manMANPATH/usr/local/MANPATH/usr/local/share/manMANPATH /usr/X11R6/manMANPATH/usr/local/mysql/man/

Our help documents are divided into chapters. different chapters indicate different meanings. To understand the meanings of different chapters in the help document, we can use the [man] command to quickly locate the desired content.

View content.

1. Check the commands in what chapters? Use whatis to retrieve the whatis databases database. The help document of the newly installed program is not recorded in the database. In Linux, makewhatis is used to generate the database. The system makes the database generation action a periodic task of the system. The task of generating whatis data is executed at 04:22 every Sunday. Therefore, the program we just installed cannot find many chapters on the command using whatis command. To view the information, run the makewhatis command to generate whatis databases.

[Root @ node2 ~] # Whatisshutdownshutdown (2)-shutdownpartofafull-duplexconnectionshutdown (3 p)-shutdownsocketsendandreceiveoperationsshutdown (8)-bringthesystemdown

2. The meaning of the chapter is described as follows:

Man1 USER command man2 System Call man3 Library call man4 Device File man5 configuration file man6 game man7 miscellaneous man8 management command

2. Use [man N] to view the content of the help document at will.

[Root @ node2 ~] # Man8shutdown

3. Use [help command] to view how to use the command. It is not as detailed as man shows.

[Root @ node2 ~] # Shutdown -- helpshutdown: invalidoption --- Usage: shutdown [-akrhHPfnc] [-tsecs] time [warningmessage]-a: use/etc/shutdown. allow-k: don 'treallyshutdown, onlywarn. -r: rebootaftershutdown. -h: haltaftershutdown. -P: haltactionistoturnoffpower. -H: haltactionistojusthalt. -f: doa 'save' reboot (skipfsck ). -F: Forcefsckonreboot. -n: donotgothrough "init" butgodownrealfast.

The help document of an application usually consists of different paragraphs. Each section describes different content of the application. To understand the meaning of each section in the help document, we can quickly find the content we want to read.

Manual section: 1. NAME command NAME 2. DESCRIPTION command function details 3. OPTIONS all OPTIONS 4. FILES configuration FILES related to the current command 5. EXAMPLES Example 6. SYNOPSIS format 7, other manuals for SEEALSO reference

Note:

If you want to quickly know how to use command, you can view the EXAMPLES section of the help manual. The Command help manual contains many characters. How can we locate the EXAMPLES character?

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

1. Enter "/keywork" to search from the beginning to the end of the document. The specified character is highlighted.

2. Enter "? Keywork "Searches from the end of the document to the header, and the specified character is highlighted.

When we find that many characters appear in the document, we can press some "keys" to quickly display the next searched character.

1. N key: opposite to the SEARCH Command, the next keyword found is displayed.

2. n: the key is the same as the search command. The next keyword is displayed.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.