In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
In this issue, the editor will bring you about the five commonly used operation methods of Bash historical records. The article is rich in content and analyzes and describes for you from a professional point of view. I hope you can get something after reading this article.
As we all know, there are many dazzling records of shortcuts in Bash history. In fact, these shortcuts can greatly improve the efficiency of our study and work. If you find these methods difficult to remember, you can learn them step by step and learn only a little every day, so that you can easily master them. The following editor will choose the five most commonly used Bash history operations for you to introduce.
1. The last parameter:! $
If you only want to learn one shortcut from this article, this is it. It replaces the last argument of the last command to your command line.
Look at this:
AHA, I wrote the wrong file name "wrongfile" in the command. I should use the correct file name "rightfile" instead.
You can retype the previous command and completely replace "wrongfile" with "rightfile". However, you can also type:
This order can also work.
There are other ways in Bash to do the same thing through shortcuts, but this technique of reusing the last argument of the previous command is the one I use most often.
2. Search and replace:!: gs
This searches for the referenced command and replaces the character between the first two / with the character between the last two /.
Suppose I want to tell someone that my s key doesn't work, but instead outputs f:
And then I realized that the f keys here are all wrong. To replace all f with s, I can type:
It works not only on individual characters. I can also replace words or sentences:
Test it
To show you how to combine these shortcuts, do you know what these command fragments will output?
3. All parameters:!: 1 color $
Suppose I run a command like this:
The parameter is correct. However, I want to match "ping" or "pong" in the file, but I use grep instead of egrep.
I started typing egrep, but I didn't want to re-enter other parameters. Therefore, I can use the!: 1 color $shortcut to retrieve all the parameters of the previous command, from the second (remember that their index starts at zero, so it is 1) to the last (represented by $).
You don't have to use 1Mel $to select all the parameters; you can also select a subset, such as 1-2 or 3-9 (if there are so many parameters in the previous command).
4. The last parameter on the penultimate line:!-2Rank $
The above shortcut is very useful when I know how to correct my command immediately after I make a mistake, but I often run another command after the original command, which means that the last command is no longer the one I want to quote.
For example, using the previous mv example, if I check the contents of the folder through ls to correct my error:
I can no longer use the! $shortcut.
In these cases, I can be in! Then insert-n: (where n is the number of commands to be traced back in the history) to get the final argument from the older command:
Similarly, once you have learned it, you may be surprised at how often you need to use it.
5. Enter the folder:! $: h
On the face of it, this doesn't look very useful, but I use it dozens of times a day.
Imagine that the command I run looks like this:
The first thing I might want to do is go to the / etc folder, look at its contents and find out what I did wrong.
I can do this in the following ways:
This means: "get the last argument of the previous command (/ etc/system) and delete its last filename part, leaving only / etc."
These are the five common Bash historical record operations shared by the editor. If you happen to have similar doubts, please refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.