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

Detailed explanation of the usage of history

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

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

Detailed explanation of the usage of History

Function: display or manipulate a list of history

Usage: history [- c] [- d offset]

History-anrw [filename]

History-ps arg [arg...]

Parameter options:

-c: clear the history

What is cleared is the history in memory, the history still exists in the file, and you can see the history after logging back in.

There are two ways to completely erase the history:

1. Clear the history of all users: add HISTSIZE=0 to the / etc/profile file

Clear the history file for a single user: add it to the. bash_profile file in the user's home directory

Enter HISTSIZE=0.

two。 Delete the file that holds the history, and then execute the history-c command

-d: delete the command specified in the history

History-d 3 (delete the third command)

History+ digit

Display the corresponding number of historical commands

-a:

Write the newly added command in memory to the document (.bash _ history)

-n: read the unread lines in the history file to the history list

Open two terminals and write the history list of one terminal to the (- a) history file (.bash _ history)

Another terminal executes the history-n command to display the command history on its terminal calendar

In the history list

-r:

Read the history file and attach it to the history list

-w:

Save the history list to a file (if no file exists, the file will be created; if the file has content

The content will be overwritten)

-p: chicken rib function!

[root@localhost testdir] # history-p cat

Cat

-s:

Falsify orders in history and not carry them out

Command history-related environment variables

Note: the following command needs to log out of the system and take effect after re-logging in. Typing the command directly disappears after exiting the system, and writing .bash _ profile is permanently valid.

HISTSIZE: number of command history entries

[root@localhost ~] # echo $HISTSIZE

one thousand

The definition file is in / etc/profile, enter

~] # nano / etc/profile

Add HISTSIZE=XXX to it to define the number of historical records

HISTFILE: specifies the history file. Default is / root/.bash_history.

[root@localhost ~] # echo $HISTFILE

/ root/.bash_history

You can modify the history file path of HISTFILE in .bash _ profile

HISTFILESIZE: the number of entries recorded in the command history file. The default is 1000, which can be modified in .bash _ profile

[root@localhost ~] # echo $HISTFILESIZE

one thousand

By adding HISTSIZE=XXX to it, you can define the number of command history files.

HISTTIMEFORMAT: display history list time (initial value is empty)

Nano editable .bash _ profile content

Add HISTTIMEFORMAT= "% F% T" and the time will be displayed in its history list.

HISTTIMEFORMAT= "`hostname` F% T" with hostname added

HISTIGNORE: ignore display history command

HISTIGNORE= "str1;srt2;."

Stop executing this command: HISTIGNORE= ""

Control how command history is recorded

HISTCONTROL=ignoredups, ignoring repeated history commands (same in succession)

HISTCONTROL=ignorespace, ignore the history command that begins with a space

HISTCONTROL=ignoreboth, the merger of the last two

HISTCONTROL=erasedups, delete duplicate command

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

Network Security

Wechat

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

12
Report