Shell Command Line Operation, shell Command Line

Source: Internet
Author: User
Tags superuser permission

Shell Command Line Operation, shell Command Line
1.1 shell prompt

[Me @ linuxbox ~] $

If the last character is "#", it indicates that the current terminal session has the superuser permission. Use the root user to log on or use a terminal that provides the superuser permission to obtain this permission.

The prompt is defined by the environment variable named PS1 (prompt string 1.

1.2 auto-completion

Auto-completion can be applied to path names, variables (words starting with $), and user names (~ Command (the first word in the command line), host name (the word starts with @, only valid for the host name under/etc/hosts)

Command Function
Alt-$ Display all possible items. Equivalent to pressing two tabs
Alt -* Insert all possible matches

 

 

 

1.2 command line history

The history command outputs historical records directly. The default value is 500.

History command

Command Function
Ctrl-P Move to the previous history, equal to the upper arrow
Ctrl-N Move to the next historical record, equal to the down arrow
Alt-< Move to the beginning of history
Alt-> Move to the end of the history, that is, the current command line
Alt-P Non-incremental search. Enter a search string and Enter to start searching.
Alt-N Forward non-incrementing search
Ctrl-O The execution history item. After the execution, it jumps to the next item. Used to execute a series of historical records
Ctrl-R Searches for historical records in reverse increments. searches for the next matching item.
Ctrl-J Copy the search content to the current command line (you can also copy the search content by pressing the left and right arrow keys. If you press Enter, the command is executed immediately)
Ctrl-G or C Exit search
!! Repeat the last command, which is equivalent to the up arrow + Enter
! Number Execute the command line number of the history record
! String Execute the latest history records starting with string
!? String Execute the latest history containing string

 

 

 

1.3 copy and paste

* You cannot use Ctrl-c or Ctrl-v.

Copy Paste
Left click to select text (or double click to select words) Middle mouse
Ctrl-Shift-c Ctrl-Shift-v
Ctrl-Insert Shift-Insert

 

 

 

 

1.4 virtual terminal

Ctrl-Alt-F1 ~ F6: switched from a graphic desktop system to 1 ~ Virtual terminal 6

Alt-F1 ~ F6: in 1 ~ Switch between virtual terminals on the 6th

Alt-F7: returns from virtual terminal to graphic desktop

1.5 wildcard characters

It is called wildcards or globbing and used to match a group of file names. It can be used with any command that uses a file name as a parameter.

Note: exercise caution when using the character range notation [A-Z] [a-z]

Wildcard Matching item
* Match any number of characters (including 0)
? Match any character (excluding 0 characters)
[Characters] Match any character set
[! Characters] Match any character that does not belong to the character set
[[: Class:] Match any character in the class

 

 

Character class Description
[: Alnum:] Letter set or number set
[: Alpha:] Letter Set
[: Digit:] NUMBER SET
[: Lower:] Lowercase letter set
[: Upper:] Uppercase letter set

 

 

 

 

 

 

1.6 redirection

Linux provides standard input "0", standard output "1", and standard error "2 ".

">": Redirects the standard output to the file. The content of the original file is cleared first.

Using "> filename" will delete the file content

"<": Reads the file content as a standard input.

">": Redirects the standard output to a file. The append mode is used.

"|": MPS queue. The standard output of the previous command is used as the standard input for the next command.

 

Redirection of standard output and standard errors at the same time:

Command> file 2> & 1

Or the command &> file supported by the new version of bash

The redirection of a standard error occurs after the standard output redirection, so command 2> & 1> file is incorrect.

Ignore output: redirects the output or standard error to the file/dev/null.

Ignore all outputs: command>/dev/null 2> & 1

Ignore error: command 2>/dev/null

1.7 extensions

Each shell command is extended before execution ). Echo can be used to verify the extended results. These extensions include:

Extension of path name (using wildcards)

Wave Line expansion (~ Or ~ User, which is extended to the user's main directory)

Arithmetic extension, $ (expression). It must be an integer operation. It supports four arithmetic operations and the remainder "%", and the power "**". Ignore spaces.

Curly braces Extension

$ Echo {1 .. 5} outputs 1 2 3 4 5

$ Echo {G .. A} output G F E D C B

$ Echo {A {1, 2}, B {3, 4} output A1 A2 B3 B4

Parameter extensions, such as $ PATH

Command replacement, such as $ (ls) or 'LS'

1.8 reference

Reference can avoid Shell extension. References weak References containing double quotation marks and strong references with single quotation marks.

Weak reference: some special characters have no special meaning. The dollar sign "$", Backslash "\", and quotation mark "'" are reserved "'". Therefore, word separation, pathname extension, wavy line extension, and curly brackets extension are invalid. Parameter extension, arithmetic extension, and command replacement are still valid.

Strong reference: suppress all extensions.

Escape Character "\": outputs "$", "\", "'", or "\ n" in weak references. Eliminate the meaning of shell special characters in the command line, such as "$ ","! "," & ", Space

1.9 shell shortcut key move cursor
Key combination Function
Ctrl- Cursor to first line
Ctrl-E Cursor to end of line
Ctrl-F Move one character forward, equivalent to the right arrow
Ctrl-B Move one character behind, equivalent to the left arrow
Alt-F Move one word forward and locate the word
Alt-B Move one character behind and locate the first letter
Ctrl-L Clear the screen and move the cursor to the beginning of the line, which is equivalent to clear

 

 

 

 

 

 

 

Modify text
Key combination Function
Ctrl-D Delete the character at the cursor
Ctrl-T The character at the cursor matches the character above
Alt-T Match the word at the cursor with the previous word
Alt-L From the cursor to the end of the word to decrease the write size
Alt-U Change from cursor to end to uppercase

 

 

 

 

 

 

Cut and paste (yanking)

The cut content is in the buffer zone of kill-ring.

Key combination Function
Ctrl-K Cut from cursor to end of line
Ctrl-U Cut from cursor to first line
Alt-D Cut from cursor to current end
Alt-Backspace Cut from the cursor to the word header. If it is already at the beginning, cut the previous time
Ctrl-Y Paste

 

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.