Search Suggest

Bài đăng

Some History Command Hacks

How to display TIMESTAMP in history

# export HISTTIMEFORMAT='%F %T '
# history   (In the output you will find date & time before the command that is executed)

To make this persistent, 
# export HISTTIMEFORMAT='%F %T ' >> /etc/profile

How to ignore some commands in history (not let history to record the commands we execute)


# export HISTIGNORE=ignorespace

Type some commands like ls -l, date, time, who, etc., then type fdisk -l with a leading space in the front before pressing enter. (Ex. #   fdisk -l)

# history   (In the output you will find fdisk command is not recorded in history file)

To make this persistent, 
export HISTIGNORE=ignorespace >> /root/.bash_profile


How to ignore duplicate commands in history (not let history to record the duplicate of the commands we execute) (not recommended in production)


# export HISTIGNORE=ignoredups

Type the command cal 5 times continuously then execute history command

# history   (In the output you will find cal command is recorded only once in history file, because we are ignoring the duplicate entries)

To make this persistent, 
export HISTIGNORE=ignoredups >> /root/.bash_profile



How to set limitations for history file size and number of commands to record 

# export HISTSIZE=100        (Only 100 last commands of the current session would be recorded)
# export HISTFILESIZE=2500    (History file size would keep 2500 commands)

# history   (In the output you will find fdisk command is not recorded in history file)

To make this persistent, 
export HISTIGNORE=ignorespace >> /root/.bash_profile

Đăng nhận xét