Summarize the 8 tips you use frequently with shell command line

Source: Internet
Author: User
Tags aliases clear screen

Original blog, reproduced please indicate the source

The shell is the command interpreter.

See which shells are supported by this system


1 Tab Command completion

This almost every time can be used, for example, I have a file called file.txt, assuming that the folder only has a file name beginning with F, then I enter F and then tab will be self-completion file.txt


22 Shortcut keys

Ctrl+l Clear Screen

Ctrl+u Clear a row (the part before the cursor)

3 Command aliases

Alias: View the current alias


Define a new alias, which defines the alias of the Delete folder Xrm


Of course. This definition is defined temporarily, and is not written to the file. After each reboot, it's time to alias again.

Be able to speak your own defined aliases written in configuration file ~/.BASHRC


Remove an alias with Unalias


4. Input and output redirection

is to write the contents of the output to another place. Or get an input from one place

Output redirection:

[Email protected] ~]# ls-l >>/dev/null

Redirect the output to/dev/null, where you can understand that/dev/null is a black hole and redirects to it won't print.


Symbol >> is empty the original content and then write

Symbol > is appended at the end of the original content


Input redirect

Symbols <

/dev/tty This file is often used to redirect to a terminal, which is very useful for input

Read Password </dev/tty reading password from terminal

For example, I want to broadcast the contents of file.txt.


Error output redirection, only redirects when an error is encountered

Frequently used processing is to generate the relevant log file

Like what. When you back up the server file. It is often chosen when after midnight server has very little access to the time when you are still dreaming, so it is important to redirect the wrong information.

So the next day, you just have to look at the wrong files and know what's wrong.

Cp–r/usr/backup/2>/bak.error


5 Piping

A pipeline is one output as an input. Often used in step-by process

Like what

LS-/etc |more; paging through the contents of a file Ls–l/etc | grep init; Extract ls–l/etc with command run results | grep init | Wc–l; The WC is used to calculate how many rows


Here's a brief explanation of the WC command.

The WC command is used to count how many rows. Number of words. Number of characters

WC #会依次输出 Number of lines, number of words, and number of characters

Wc-l #行数

wc-w# number of words

Wc-c #字符个数


6 Command Connector

&& the previous command runs successfully and the latter command runs

|| The previous command failed to run. The latter command will not run


7 Command Substitution symbols

The one on the top of the Keyboard tab. Note that it is not an argument

When a command substitution symbol is encountered, the command replaces the statement in the symbol with the command, and then returns the result to the previous layer



8 reading the beginning or end of a file

Head-n file first few lines

Tail-n file files after several lines

Tail-f file continues to observe the end of a document. Suitable for dynamic observation of log files


Of course, we can also work with grep to see only the log information that includes the specified characters

Finally, attach the previously written link to the awk,grep,sed

grep command Specific explanation-9 classic usage scenarios

SED command specific explanation

awk Command High Speed primer


Summarize the 8 tips you use frequently with shell command line

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.