Summarize your own 8 tips used in shell command line

Source: Internet
Author: User
Tags 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 can be used almost every time, for example, I have a file called file.txt, if only one file name in this directory starts with F, then I enter F and then tab will automatically fill out 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 to delete the directory Xrm


Of course, this definition is just a temporary definition and is not written to the file, and is re-alias after each reboot.

Can speak a custom alias written in configuration file ~/.BASHRC


Remove an alias with Unalias


4. Input and output redirection

is to write the output to another place, or to get an input from a 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 here are not printed.


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 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, redirect only when an error is encountered

The usual processing is to generate the relevant log file

For example, when backing up a server file, it is often selected when the after midnight server has very little access, and you are still dreaming, so it is important to redirect the wrong information. So the next day you go to work, just look at the wrong files and know what's wrong.

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


5 Piping

A pipeline is one output that is used as another input, often in step processing

For example

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


Here's a brief explanation of the WC command.

The WC command is used to count the number of lines, the number of words, the 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 executes successfully and the latter command executes

|| The previous command failed to execute after a command was executed


7 Command Substitution symbols

On the top of the Keyboard tab. • Note that it is not a quotation mark

When a command substitution symbol is encountered, the statement in the command substitution symbol is executed as a command, and the result is returned 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 continuously observes the end of a document and is suitable for dynamic observation of the log file


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

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

grep command Detailed-9 Classic usage scenarios

SED command detailed

awk Command Quick Start


Summarize your own 8 tips used in 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.