linux-shell (5) -Bash multi-command sequential execution and pipe character

1: Multi-command sequential execution (can simplify operation)

Multi-command executor format effect
;(semicolon) Command 1; Command 2 Multiple commands are executed sequentially without any logical connection between commands
&& Command 1 && Command 2

Logical AND, when command 1 is executed correctly, command 2 will be executed, when command 1 is executed incorrectly, command 2 will not be executed

|| Command 1 || Command 2 Logical OR, when Command 1 is executed incorrectly, Command 2 will be executed, when Command 1 is executed correctly, Command 2 will not be executed

 

Example: relevant;

Sequential execution of multiple commands can simplify operations such as the dd command. Adding date before use and adding date after use facilitate subsequent inspections.

The dd command is also a function of copying, but the function is more powerful. In the case of cp, you can only copy files.

The dd command is used to copy files and convert and format the contents of the original files. The dd command is very powerful. For some low-level problems, the dd command can often get unexpected results. More often used dd to back up raw equipment. However, it is not recommended. If you need to back up oracle raw devices, you can use rman backup, or use third-party software backup, using dd, it is not easy to manage.

It is recommended to use dd to operate the physical disk when necessary. If it is a file system, it is more convenient to use other commands such as tar  backup  cpio . In addition, when using dd for disk operations, it is best to use block device files.

dd if = input file of = output file bs = byte count = number

Options: if = input file Specify the source file or source device.

          if = output file Specify target file or target device

          bs = number of bytes Specify how many bytes are input / output at a time, that is, treat these bytes as a data block

          count = number specifies how many data blocks to input / output

Example: Related &&

Example: You can use the command && echo yes || echo no to determine whether this command is correct. Can be used in the program, the positional relationship of && and || cannot be changed. The reason is as follows. If you switch positions, echo yes will also be displayed when the command is wrong.

2: Pipe character:

Command format: Command 1 | Command 2 (Command 1 must have correct output)

Indicates the correct output of command 1 as the operation object of command 2

For example: ll (ls -l) -a / etc / | more (since more can only display the text content of the file in split screen, if you use it like this, you can display the content displayed by command 1)

Usage of more

The more command is a text editor based on the vi editor, which displays the contents of the text file page by page in a full-screen manner and supports keyword positioning operations in vi. Several shortcut keys are built into the more list. Commonly used are H (for help information), Enter (roll down one line), space (scroll down one screen), Q (quit command).

This command displays one screen of text at a time, and stops after a full screen, and a prompt message appears at the bottom of the screen, giving the percentage of the file that has been displayed so far: --More-- (XX%) You can use the following different methods Answer the prompt:

Press the Space key: display the next screen of text. Press the Enier key: Only the next line of text is displayed. Press the slash character |: Then enter a pattern, you can find the next matching pattern in the text. Press the H key: a help screen is displayed with relevant help information on the screen. Press B key: display the previous screen content. Press the Q key: Exit the rnore command.
 

For example: netstat -an | grep ESTABLISHED

Use of netstat;

The netstat command is used to print the status information of the network system in Linux, allowing you to know the network status of the entire Linux system.

grep command: grep [options] "search content" file name ((global search regular expression (RE) and print out the line, comprehensive search regular expression and print out the line) is a powerful text search tool, it can Use regular expressions to search for text, and print the matching lines. It can only be found in the file, which is more powerful after using the pipe character)

                      -n: output line number

                      -v: reverse search

                     --color = auto The searched keywords are displayed in color

Published 158 original articles · Like 10 · Visitors 20,000+

Guess you like

Origin blog.csdn.net/ab1605014317/article/details/105603616