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

How to repeatedly execute historical commands in Linux system

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article will explain in detail how to repeatedly execute historical commands in the Linux system. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

Before we officially begin, let's casually execute a few commands for later demonstration. In order to save space, the implementation results are not listed for the time being.

$ls-l $pwd$ date$ uname-a method 1VOF!

Yes, two exclamation marks are also a command, and it repeats the last command.

$!

This command is equivalent to the following effect:

$!! uname-aLinux VM_0_16_centos 3.10.0-514.26.2.el7.x86_64 # 1 SMP Tue Jul 4 15:04:05 UTC 2017 x86 "64 GNU/Linux

If you need root permission, you can also add sudo in front of it.

$sudo! Method 2.

If we enter a lot of commands in the course of the operation, what if we want to repeat one of them now? There is a simple way to use the up and down arrows to look it up, but if you type too many commands before, it will take a long time to search.

At this time,! the command of un shows its function. Remember, this un is not fixed, it represents the first few characters of the command you want to repeat.

For example, in this routine, we want to repeat the command uname-a by doing this:

$! ununame-aLinux VM_0_16_centos 3.10.0-514.26.2.el7.x86_64 # 1 SMP Tue Jul 4 15:04:05 UTC 2017 x86 "64 GNU/Linux

If you have entered more than one command that starts with un, you may need to enter a few more characters.

$! uname method 3

This method is more flexible.!-1 means to repeat the last command,!-2 means to repeat the penultimate command, and!-n means to repeat the penultimate instruction.

$!-1uname-aLinux VM_0_16_centos 3.10.0-514.26.2.el7.x86_64 # 1 SMP Tue Jul 4 15:04:05 UTC 2017 x 86 "64 GNU/Linux$!-3 # Note, the previous!-1 is also an instruction, so the penultimate instruction is date, not pwddateSun May 19 18:30:26 CST 2019 method 4:ctrl+r

Ctrl+r this shortcut key allows you to search for all the commands you have entered before. In fact, Liangxu prefers this shortcut key because it will let you see the command you are about to execute. And if it is! In the case of a command, it is to execute the last command directly. If this command is safe, it would be tragic to have a command like rm-rf / *.

If I want to repeat uname-a now, we can press the ctrl+r key combination first, and then type'u'n'a'in turn. If you have entered fewer commands before, you can basically find the command you want to enter by typing a u or n.

(reverse-i-search) `uplink: uname-a

After you find it, hit enter again, and you can repeat the command you want to enter.

If you want to make some minor changes to the command you find, just tap the left or right arrow.

Methods 5:ctrl+p or ctrl+n with ctrl+o

If you have advanced lazy cancer and don't want to type any more letters, you just want to find the command you want and execute it. How do you do it?

As mentioned earlier, for commands entered in history, you can use the up and down arrows. But this is not the most efficient, we can use ctrl+p and ctrl+n to achieve the same effect. This is more efficient because you don't have to lift your hand and move it to the arrow area.

After finding the desired command through the key combination of ctrl+p/n, we can press ctrl+o to execute the command. This key combination is not quite the same as enter because it jumps to the last command in addition to carriage return. By constantly ctrl+p/n and then ctrl+o, you can repeat the commands you want to execute efficiently.

On how to repeat the implementation of historical commands in the Linux system to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

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