In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you "how to use Bash history commands in linux", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to use Bash history commands in linux" this article.
Bash's history command exceeds all other Linux Shell historical interfaces in terms of the number of features it provides.
Bash has a rich history. In other words, it is an ancient shell and an older Shell (Bourne shell) predecessor, but it also has a great history command that provides more features than all other shell historical interfaces. The Bash version of history can perform reverse search, quick call, rewrite history, and so on.
The history command is different from many other commands. You may be used to putting commands as executables in common system-level locations, such as / usr/bin, / usr/local/bin, or ~ / bin. The built-in history command is not in your PATH and has no physical location:
$which history which: no history in [PATH]
Instead, history is a built-in function of shell itself:
$type historyhistory is a shell builtin$ help historyhistory: history [- c] [- d offset] [n] orhistory-anrw [filename] orhistory-ps arg [arg...] Display or manipulate the history list. [...]
For this reason, the historical features in each shell are unique, so the features you use in Bash may not be available in Tcsh or Fish or Dash, and the features used in these shell may not be available in Bash. In some cases, knowing what Bash can do may inspire other shell users to create interesting modifications to replicate Bash behavior and may unlock Bash features that you never knew about.
Check your Bash history
The most basic and frequent use of the history command is to view the history of shell sessions:
$echo "hello" hello$ echo "world" world$ history 1 echo "hello" 2 echo "world" 3 history event indicator
Event indicator Event designator searches your history by event. In this case, "event" refers to a command recorded in history, delineated by a newline character. In other words, one event at a time, marked with an index number.
Event indicators mostly start with an exclamation point, sometimes called "bang" (!).
To rerun a command from your history, use an exclamation point, followed by (no space between) the index number of the desired command. For example, suppose line 1 contains the command echo "hello" and you want to run it again:
1echo "hello" hello
You can use relative positioning to provide a negative line number based on your current position in history. For example, return to the penultimate entry in history:
$echo "foo" foo$ echo "bar" bar$ echo "baz" baz$!-3echo "foo" foo
If you just want to go back to one line, you can use shorthand! Instead of!-1. This saves keystroke time!
$echo "foo" $!! echo "foo" foo string search
You can also search for specific strings for items and, in turn, search for commands to run. To search for commands that start with a specified string, use an exclamation point, followed by (no spaces) the string you want to search for:
$echo "foo" $true$ false$! echoecho "foo" foo
You can also search anywhere (not just at the beginning) for a command that contains the string. To do this, please use it as before! Add the string to search for, but surround both ends of the string with a question mark (?). If you know the string followed by a newline character, you can omit the last question mark (that is, the last character entered before pressing enter):
$echo "foo" $true$ false$!? foo?echo "foo" foo string substitution
Similar to searching for a string at the beginning of a line, you can search for a string and replace it with a new string to change the command:
$echo "hello" hello$ echo "world" world$ ^ Hello^ Fooecho "foo" foo makes history useful
In Bash, the history command goes far beyond what is described here, but it's a good start to get used to using your history instead of just using it as a reference. Use the history command frequently and try something you can do without entering a command. You might be surprised!
The above is all the contents of this article entitled "how to use Bash history commands in linux". 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
[root@localhost test ~] $fuserNo process specification givenUsage: fuser [- a |-s |-c] [- n SPACE
© 2024 shulou.com SLNews company. All rights reserved.