Linux/Unix Shell shortcut keys)

Source: Internet
Author: User

Sometimes, we need to repeat the previous commands in Bash. Of course, you can use the up arrow key to view commands that have been run before, but this article introduces some better ways, such !!,! A ,! Number ,! -Number ,! $, Ctrl + r, and other shortcut keys. This article also provides examples to illustrate how to correctly use these shortcut keys.

AD:

Sometimes, we need to repeat the previous commands in Bash. Of course, you can use the arrow keys to view commands that have been run before. But here are some better ways:

1 )!! : Execute the previous command repeatedly.

2 )! A: repeat the previous a-led command.

3 )! Number: repeat the previous command to record the number as number in the history Table.

4 )! -Number: number of the first command before repeated execution

5 )! $: Get the last item in the previous command

6) use Ctrl + r to enter the historical search mode and query a previous command in the history Table. After finding the command to be executed repeatedly, press the Enter key to repeat the command parameters (that is, the first 5th items in the previous point)

Let's take an example: mkdir/exampledircd! $

In this example, the first line of command will create a directory, and the second line of command will go to the directory just created.

Here, "! $ "Is used to repeat the parameters of the previous command.

In fact, not only can the command parameters be repeated, but the Command Options can also be.

In addition, the Esc +. Shortcut Keys can switch between these command parameters or options.

The shortcut key for editing: Ctrl +:

Position the cursor at the beginning of the command Ctrl + e:

Opposite to the previous shortcut key, move the cursor to the end of the command Ctrl + u:

Cut the content before the cursor Ctrl + k:

In contrast to the previous shortcut key, cut the content after the cursor Ctrl + y:

Paste the contents cut by Ctrl + u and Ctrl + k Ctrl + t:

Exchange the order of the two characters before the cursor Ctrl + w:

Delete the parameter (option) or content on the left of the cursor Ctrl + l:

Clear screen Ctrl + d: the input is complete.

In shell, it is equivalent to an exitCtrl + c: keyboard interrupt request.

Ctrl + s & Ctrl + q:

Pause/resume screen output Ctrl + n (pause ):

Display the next command Ctrl + p (SUCCESS ):

Display the previous command Ctrl + B:

Move Ctrl + f back:

Move Ctrl + shift + forward:

Terminal scroll down Ctrl + shift + Terminal:

Terminal scroll up Shift + pgup/pgdown:

Terminal page turning and rolling processing jobs

First, use the Ctrl + z shortcut to suspend the command being executed. If you want the process to be executed in the background, you can execute the bg command. The fg command allows the process to return to the foreground again.

Run the jobs command to view which processes are executed in the background.

You can also use the job id in the fg or bg command,

Example: fg % 3

For example, bg % 7 is replaced by the replacement command.

First look at the example: du-h-a-c $ (find.-name *. conf 2> &-)

Note the section in $ (), which tells Bash to run the find command and then use the returned result as the du parameter.

Process replacement

Let's take a look at the example: diff <(ps axo comm) <(sshuser @ host ps axo comm)

This command compares processes running in the Local System and remote system.

Note the section in <.

Xargs example:

Find.-name *. conf-print0 | xargs-0 grep-l-Z mem_limit | xargs-0-I cp {}

{}. Bak this command backs up all. conf files in the current directory.

MPs queue

The following is a simple example of using pipelines:

Ps aux | grep init here,

The '|' operator redirects the output of ps aux to grep init.

There are two more complex examples:

Ps aux | tee filename | grep init and: ps aux | tee-a filename | grep init Save the standard output as a file. You can save the standard output content of the command to a file,

For example, note the ">" symbol in ps aux> filename.

You can also append the output content to an existing file: ps aux filename

You can also split a long line: command1 | command2 |... | CommandN> tempfile1 cat tempfile1 | command1 | command2 |... | CommandN>

Redirection and combination

Example of redirection stream: ps aux 2> & 1 | grep init

The number here represents: 0: stdin1: stdout2: In the command above sterr, "grep init" not only searches for the standard output of "ps aux", but also searches for the sterr output.

You can also append the output content to an existing file: ps aux filename

You can also split a long line: command1 | command2 |... | CommandN> tempfile1 cat tempfile1 | command1 | command2 |... | CommandN>

Some common shortcut keys in Ubuntu:

Window Management Win + E shows all desktops, which is convenient to choose between left and right.

Ctrl + Alt + →/← switch between different workstations

Ctrl + Alt + Shift + →/← Move the current window to different workstation

Alt + Shift + ↓ display the current window in a cool way

Ctrl + Alt + D Display desktop/restore current window

Alt + Tab switch window

Alt + F4 close the window

Alt + F5 Cancel to maximize the window (restore the original size of the window)

Alt + F7 move the window (Note: It is invalid when the window is maximized)

Alt + F8 change the window size (Note: It is invalid when the window is maximized)

Alt + F9 minimized window

Alt + F10 maximize window

Alt + Space open the control menu of the window (click the menu icon in the upper left corner of the window)

Ctrl + Alt + F7 return to desktop

File Browser NautilusShift + Ctrl + N create a folder, which is very useful

Alt + Enter to view the properties of the selected file/folder, instead of right-clicking to select Properties

Ctrl + 1/2 change the folder view, icon view/List View

Ctrl + W disable the current Nautilus tag

Ctrl + Shift + W disable all Nautilus labels

Ctrl + T create a new tag in Nautilus

Ctrl + Page Up previous tag

Ctrl + Page Down next tag

Alt + ↑/↓ move to the parent folder/selected folder

Alt + →/move back/forward

Alt + Home move directly to the main folder

Alt + N switch to the nth tag (N is a number)

Hide Nautilus sidebar on/off F9

Ctrl + H switch to show hidden folders

Common shortcut key Ctrl + N in the application to create a window

Ctrl + X cut

Ctrl + C copy

Ctrl + V Paste

Ctrl + Z undo the previous operation

Ctrl + Shift + Z redo the one-step Undo operation

Ctrl + S save

Other Ctrl + Alt + L lock screen

Alt + F1 open application menu

Alt + F2 open the run application dialog box

Win + scroll wheel to zoom in/out the screen

PrintScreen full screen

Alt + PrintScreen current window

Ctrl + Alt + Shift + Fn terminal N or analog terminal N (n and N are numbers 1-6)

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.