In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how to use the history command in Bash, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
History is a built-in command
The history command is different from many other commands. You may be used to placing commands as executables in common system-level locations, such as / usr/bin,/usr/local/bin or ~ / bin. However, the built-in history command is not in the path saved by your environment variable PATH.
In fact, the history command is not saved in a physical location:
$which history which: no history in [PATH]
History is actually a built-in function of Shell itself:
$type history history is a shell builtin $help history history: history [- c] [- d offset] [n] or history-anrw [filename] or history-ps arg [arg...] Display or manipulate the history list. [...]
Because history is a built-in function for Shell, the history function for each Shell is unique. As a result, features that you can use in Bash may not be available in Tcsh,Fish or Dash, just as features that can be used in Tcsh,Fish or Dash may not be available in Bash.
View your Bash command history
The most basic and frequent use of the history command is to check the command history of your Shell session:
$echo "hello" hello $echo "world" world $history 1 echo "hello" 2 echo "world" 3 history
Event prompt
Event prompt (!) It searches for history by event. The event here refers to every order recorded in the history record. In other words, it is an one-line command and is marked with a numeric index for reference.
To rerun a command in the history, use! Just add (no spaces) the index number in front of the command you want to run. For example, suppose the first instruction in the history is echo hello, and then you want to rerun it:
! 1 echo "hello" hello
You can also use relative positioning by providing negative rows from the current position in the history. For example, return to the penultimate command in history:
$echo "alvin" alvin $echo "hello" hello $echo "world" world $!-3 echo "alvin" alvin
If you only want to return to the previous command, you can use the abbreviation! To replace!-1. This saves the time of pressing a key!
$echo "alvin" alvin $! Echo "alvin" alvin
String search
You can also search for a command in the history and run it with a specific string.
If you want to search for commands that start with a specific string, use! Directly add (no spaces) the string you want to search for:
$echo "alvin" alvin $true $false $! echo echo "alvin" alvin
You can also search for commands that contain specific strings anywhere. To do this, you just need to use! Add directly to the front and rear ends? Just surround a specific string, like this:
$echo "alvin" alvin $true $false $! alvin? Echo "alvin" alvin
If you know that the string you want to search for is at the end of the command, you can omit the? after the string, like this:
$echo alvin alvin $!? alvin echo alvin alvin
It is worth noting that if there is more than one command in the history that contains the target string, it executes only the last of the eligible commands:
$echo "hello world" hello world $echo "hello alvin" hello alvin $! hello? Echo "hello alvin" hello alvin
String substitution
You can change the command by searching for a specific string and replacing it with a new string:
$echo "hello" hello $echo "world" world $^ Helo Alvin echo "alvin" alvin
But it can only replace the target string that appears for the first time, and if the target string appears twice in the command, only the first occurrence will be replaced, like this:
$echo "hello hello" hello hello $^ Helo Alvin echo "alvin hello" alvin hello
As with string search, when there is more than one command in the history that contains the target string, only the last one is replaced and executed:
$echo "hello world" hello world $echo "hello" hello $^ Helo Alvin echo "alvin" alvin
Make full use of the history command
In fact, the function of Bash's history command is much more than mentioned in this article, but this is a good start for you to get used to using the history command, rather than just using history to view history. Use the history command frequently to see how much you can accomplish with only the history command without typing in specific instructions. You'll be amazed.
The above is all the contents of the article "how to use history commands in Bash". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, 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.