Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Bash Shell

2025-04-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

Editing command

Ctrl + a: move to the beginning of the command line

Ctrl + e: move to the end of the command line

Ctrl + f: move forward by character (right)

Ctrl + b: move backward by character (left)

Alt + f: move forward by word (right)

Alt + b: move back by word (left)

Ctrl + xx: move between command line header and cursor

Ctrl + u: delete from the cursor to the beginning of the command line

Ctrl + k: delete from cursor to end of command line

Ctrl + w: delete from cursor to prefix

Alt + d: delete from cursor to suffix

Ctrl + d: delete the characters at the cursor

Ctrl + h: delete the character before the cursor

Ctrl + y: paste behind the cursor

Alt + c: a word that changes from cursor to uppercase

Alt + u: a word changed from cursor to all uppercase

Alt + l: a word changed from cursor to all lowercase

Ctrl + t: swap characters at and before the cursor

Alt + t: exchange the words at and before the cursor

Alt + Backspace: same as Ctrl + w, but with some differences in delimiters [thanks for rezilla correction]

Re-execute the command

Ctrl + r: reverse search command history

Ctrl + g: exit from historical search mode

Ctrl + p: the last command in history

Ctrl + n: the next command in history

Alt +.: use the last argument of the previous command

Control command

Ctrl + l: clear the screen

Ctrl + o: execute the current command and select the previous command

Ctrl + s: block screen output

Ctrl + Q: allow screen output

Ctrl + c: terminate the command

Ctrl + z: suspend command

Bang (!) Command

!!: execute the previous order

! blah: execute the most recent command that starts with blah, such as! ls

! blah:p: print output only, not execute

! $: the last parameter of the previous command, compared with Alt +. The same

! $: P: printout! contents of $

! *: all parameters of the previous command

! *: P: printout! *

^ blah: delete the blah from the previous command

^ Blah ^ Foo: replace blah in the previous command with foo

^ Blah ^ Foo ^: replace all blah in the previous command with foo

FYI:

1. Most of the Bash shortcuts described above are valid only when in emacs editing mode, and if you configure Bash in vi editing mode, it will follow vi's key binding. Bash defaults to emacs editing mode. If your Bash is not in emacs editing mode, you can set it through set-o emacs.

2. ^ S, ^ Q, ^ C, ^ Z are handled by the terminal device and can be set with the stty command.

Improve Bash's command history management: there is a problem with the default configuration of Bash. If two (or more) consoles are opened at the same time, commands executed in both consoles will not be shared with each other in history. Some command history will even be overwritten eventually. To solve this problem, add the following to the ~ / .bashrc or ~ / .bash_profile file:

Shopt-s histappend

PROMPT_COMMAND='history-a'

The first sentence is used to append the command to the history.

The second sentence is to save history when the command prompt is displayed.

Set up intelligent autocomplete function: we can already enjoy the autocomplete feature by pressing the Tab key in Bash. With the following settings, you can use the Up and Down keys to select the parameters that follow the command. Add the following to .inputrc (or create one if the file does not exist):

"\ e [A": history-search-backward

"\ e [B": history-search-forward

Set show-all-if-ambiguous on

The first two sentences use Up and Down to search in history.

The latter sentence is done automatically according to the Tab display.

If combined with Ctrl-R, it is easier to use.

Execute commands from history sometimes we need to repeat previous commands in Bash. Of course, you can use the up arrow to view commands that have been run before. But here's a better way: you can press Ctrl + r to enter the history search mode, and once you find a command that needs to be repeated, press enter.

Repeat the command parameters. Let's first look at an example:

$mkdir / path/to/exampledir; cd! $

In this case, the first line of command creates a directory, while the second line of command goes to the directory you just created. Here, the function of "! $" is to repeat the parameters of the previous command. In fact, not only the parameters of the command can be repeated, but the options of the command can also be repeated. In addition, Esc +. Keyboard shortcuts toggle these command parameters or options.

Keyboard shortcuts for editing

Ctrl + a: position the cursor at the beginning of the command

Ctrl + e: contrary to the previous shortcut, position the cursor at the end of the command

Ctrl + u: cut the contents before the cursor

Ctrl + k: contrary to the previous shortcut, cut the content after the cursor

Ctrl + y: paste the content cut by the above two shortcut keys

Ctrl + t: swap the order of the first two characters of the cursor

Ctrl + w: delete the parameter (option) or content on the left side of the cursor

Ctrl + l: clear the screen

First of all, use the Ctrl + z shortcut key to suspend the executing command. If you want the process to execute in the background, you can execute the bg command. The fg command brings the process back to the foreground. Using the jobs command, you can see which processes are executing in the background. You can also use the job id in the fg or bg command, such as fg% 3 and bg% 7

Use replacement

Command replacement first look at the example: du-h-a-c $(find. -name * .conf 2 > & -) pay attention to the section in $(), which tells Bash to run the find command and then take the returned result as an argument to du.

Process replacement still looks at the example: diff > filename. You can also split a longer line: command1 | command2 |. | commandN > tempfile1 cat tempfile1 | command1 | command2 |. | commandN > tempfile2

Standard stream: example of redirecting and combining redirected streams: ps aux 2 > & 1 | the numbers here represent grep init:

0:stdin

1:stdout

2:sterr

In the above command, "grep init" searches not only for the standard output of "ps aux", but also for sterr output.

Refer Link:

Http://linuxtoy.org/archives/bash-shortcuts.html

Http://linuxtoy.org/archives/bash_tricks.html

Http://linuxtoy.org/archives/the-best-tips-and-tricks-for-bash.html

Http://linuxtoy.org/archives/bash-command-line-editing.html

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report