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

The use of history command to display historical instruction record under linux

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article mainly explains "the use of history command display history instruction record under linux". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "the use of displaying historical instruction records with history commands under linux".

The History command is mainly used to display the contents of the historical instructions and issue the instructions in the historical records.

1 > History command syntax:

[test@linux] # history [n]

[test@linux] # history [- c]

[test@linux] # history [- raw] histfiles

Parameters:

N: number, to list the most recent n commands

-c: eliminate all history content in the current shell

-a: add the newly added history directive to histfiles, if histfiles is not added

Then the default write ~ / .bash_history

-r: read the contents of histfiles into the history memory of the current shell

-w: write the current history memory to histfiles

Linux system when you enter and execute commands in shell (console), shell will automatically record your commands in the history list, which is generally saved in the. bash_history file in the user directory. 1000 items are saved by default, and you can also change this value.

If you type history, history will show you the first 1000 history commands you used and number them, and you will see a numbered list scrolling quickly across the screen. You may not need to view all of the 1000 commands, but you can also add numbers to list the most recent n commands.

The history command in linux does not just allow us to query historical commands. We can also use related functions to help us carry out orders.

2 > run specific historical commands

History lists and numbers all the historical commands saved by bash, and we can run specific historical commands using "exclamation point followed by numbering".

Syntax description:

[test@linux] # [! number] [! command] [!!]

Parameter description:

Number: what is the meaning of the instruction

Command: the first few letters of the instruction

!: the meaning of the last instruction!

3 > History command actual combat

List all the history:

[test@linux] # history

List only the last 10 records:

[test@linux] # history 10 (Note, space between history and 10)

Use the command record number to execute the command, and execute the 99 command in the history list

[test@linux] #! 99 (! There is no space between 99)

Repeat the previous command

[test@linux] #!!

Execute the last command that starts with rpm (!? Represents a string, this String can be typed at will, Shell will search forward from the last history command, and the first matching command will be executed.)

[test@linux] #! rpm

List all history on a screen-by-screen basis:

[test@linux] # history | more

Immediately clear the records of all current history historical commands

[test@linux] # history-c

In addition to using the history command, you can also use the up and down arrow keys to flip through the command history at the prompt of the shell or GUI terminal (the down arrow will scroll forward) until you find the command you need. This allows us to easily edit one of the previous commands without having to repeat similar commands.

The History command is really useful! But you need to be careful about safety! Especially the historical records of root, which is a favorite of hackers! Because careless root will record a lot of important data in ~ / .bash_history during execution, if this file is parsed, the consequences will be unimaginable!

At this point, I believe you have a deeper understanding of "the use of history commands under linux to display historical instruction records". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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

Servers

Wechat

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

12
Report