Shell command-line operations

Source: Internet
Author: User
Tags arithmetic

1.1 Shell prompt

[Email protected] ~]$

If the last character is "#", it indicates that the current Terminal session has Superuser privileges. This permission can be obtained by logging in with the root user or using a terminal that provides superuser privileges.

The prompt is defined by an environment variable named PS1 (Prompt string 1).

1.2 Auto-Completing

Auto-completion can be applied to path names, variables (words starting with $), user names (beginning with ~), commands (the first word at the command line), host names (words begin with @, only valid for host names under/etc/hosts)

Command Role
alt-$ Displays all possible items. Equivalent to pressing TAB two times
alt-* Insert all possible matches

1.2 Command line History

The history command outputs a historical record, which defaults to 500.

History commands

Command Role
Ctrl-p Move to previous history, equal up Arrow
Ctrl-n Move to the next history, equal to the down arrow
alt-< Move to the beginning of the history record
Alt-> Move to the end of the history, which is the current command line
Alt-p Non-incremental search. Enter search string and type Enter to start search
Alt-n Forward non-Incremental search
Ctrl-o Executes the history item and jumps to the next item after execution. Used to perform a series of historical records
Ctrl-r Reverse incremental search history; Find next match when searching
Ctrl-j Copy the search content to the current command line (press the left and RIGHT arrow keys to copy, and press ENTER to execute the command immediately)
Ctrl-g or C Exit Search
!! Repeat the last command, equivalent to the UP ARROW +enter
!number command to execute history number line
! String Executes the most recent history that begins with a string
!? String Executes the most recent history that contains a string

1.3 Copy and paste

* You can't use ctrl-c and ctrl-v.

Copy Paste
left mouse button to select text (or double-click to select Word) Middle mouse button
Ctrl-shift-c Ctrl-shift-v
Ctrl-insert Shift-insert

1.4 Virtual Terminal

CTRL-ALT-F1 ~ F6: Switch to 1~6 virtual terminal by the graphical desktop system

ALT-F1 ~ F6: Switch between virtual terminals 1~6

Alt-f7: Back to the graphical desktop system by the virtual terminal

1.5 wildcard characters

Called wildcards or globbing to match a set of file names. Can be used with any command that uses a file name to make arguments.

Note: Use the character range notation sparingly [a-z][a-z]

Wildcard characters Matching items
* Matches any number of characters (contains 0)
? Match any one character (0 not included)
[Characters] Match any character within a character set
[!characters] Match any character that is not in character set
[[: Class:]] Match any character within an in-class character

Character class Description
[: Alnum:] Alphabet Set or number set
[: Alpha:] Alphabet Set
[:d Igit:] Number Set
[: Lower:] Small Letter Set
[: Upper:] Caps set

1.6 Redirects

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

">": Redirect the standard output to a file, emptying the original file contents first

Use "> filename" to delete the contents of a file

"<": Read the contents of the file as a standard input command

">>": Redirect standard output to a file, using append mode

"|" : pipe, the standard output of the previous command as standard input for the next command

Simultaneous redirection of standard output and standard errors:

Command > File 2>&1

or new bash-supported command &> file

The redirection of standard errors occurs after standard output redirection, so command 2>&1 >file is wrong.

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

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

Ignore error: Command 2>/dev/null

1.7 Extensions

Each time the shell command executes, it will be expanded (expansion). Echo makes it easy to verify the extended results. These extensions include:

Path name extension (wildcard characters are used)

Wavy line Extension (~ or ~user, extended to User's home directory)

Arithmetic extension, $ (expression), note all integer operations, support four and take remainder "%", take power "* *", ignore spaces

Curly brace Extension

$ echo {1..5} Output 1 2 3 4 5

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

$ echo {a{1, 2}, B{3, 4}} output A1 A2 B3 B4

Parameter extensions, such as $path parameters

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

1.8 References

References can avoid shell extensions. References a strong reference that contains both a weak reference and a single quotation mark.

Weak references: Some special characters lose special meaning, keep the dollar sign "$", backslash "\", anti-quote "'". Therefore, word separation, pathname expansion, wavy line expansion, and braces extension are invalidated. Parameter expansion, arithmetic expansion, and command substitution are still valid.

Strong reference: Suppresses all extensions.

Escape character "\": Output "$", "\", "" "or output escape character" \ n "in a weak reference. Eliminate the meaning of the shell special characters on the command line, such as "$", "!", "&", Spaces

1.9 Shell shortcut key cursor movement
Key combinations Role
Ctrl-a Cursor to beginning of line
Ctrl-e Cursor to end of line
Ctrl-f Move forward one character, equivalent to the right arrow
Ctrl-b Move back one character, equivalent to the left arrow
Alt-f Move forward one word, navigate to the word
Alt-b Move back one word and position to the beginning of the letter
Ctrl-l Clear the screen and move the cursor to the beginning of the line, equivalent to clear

Modify text
Key combinations Role
Ctrl-d Remove the character at the cursor
Ctrl-t The character at the cursor and the preceding character are swapped
Alt-t The word at the cursor and the previous word swap
Alt-l lowercase from cursor to Word end
Alt-u Capitalize from cursor to Word end

Cut (Killing) and paste (yanking)

A buffer in which the clipped content exists as a kill-ring

Key combinations Role
Ctrl-k Cut from cursor to end of line
Ctrl-u Cut from cursor to beginning of line
Alt-d Cut from cursor to current suffix
Alt-backspace Cut from cursor to prefix, if already at the beginning, cut one single time before
Ctrl-y Paste

Shell command-line operations

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.