当前位置:   article > 正文

Add timestamp + change history size in your linux history_addtimestamps什么意思

addtimestamps什么意思
Thread starter Rob Start date Mar 7, 2020

Tags
    bash history history 
  • 1
  • 2
  • 3
  • 4

Rob
Rob
Administrator
Staff member
Mar 7, 2020

#1
  • 1

The Linux history command is awesome by default, but you can make it better! By default, it’ll only hold about 1000 past commands, but you can increase that - you can also add time/date to it so you can see when you ran each command!

In your ~/.bashrc file, simply add some lines like:
Code:

HISTTIMEFORMAT="%F %T "
HISTFILESIZE=5000

Then, you’ll have a 5000 line history file along with timestamps! Give it a go and let me know how it goes!

After you log out and back in, you’ll see something like:
Code:

1991 2020-03-06 20:00:23 cat word_list.txt |wc
1992 2020-03-06 20:00:23 head word_list.txt
1993 2020-03-06 20:00:23 tail word_list.txt
1994 2020-03-06 20:00:23 ls
1995 2020-03-06 20:00:23 cd …
1996 2020-03-06 20:00:23 ls
1997 2020-03-06 20:00:23 cat scripts/push-changes.sh
1998 2020-03-06 20:00:23 exit
1999 2020-03-06 20:00:23 exit
2000 2020-03-06 20:00:27 history
2001 2020-03-06 20:01:08 ls
2002 2020-03-06 20:01:10 history

Everything before time/date will show the same time, but after that, it’ll show you the exact times of command run.

Recently, Ubuntu and some other distros have been changing history to 2000 lines, so if you see that in your .bashrc, either comment it out, or just directly change that to 5000.

Last edited: Mar 7, 2020
Essential Linux Command Line (my ebook / $2.99!)
Linux Tutorials (my YouTube channel)
Gun Forums: My new gun forums site

wizardLike 
  • 1

Reactions: Karthick and wizardfromoz

wizardfromoz
wizardfromoz
Super Moderator
Staff member
Gold Supporter
Mar 7, 2020

#2
  • 1

it may be worth noting for the viewers, rob, too, that if they spend a bit of time as root, they can likewise apply the above to the .bash_history that applies to root’s activities.

avagudweegend

wizard

Last edited: Apr 5, 2020

THOUGHTS FOR APRIL 2020 1. broken shoulder will take weeks to mend. 2. ON AV - nothing is bulletproof, but i wear kevlar - i use linux:D. 3. Still Beer o’clock where I live :p. Come and have a sing-along at Rock Roxx

beerLike 
  • 1

Reactions: Ca8aB and Rob
NIMMAKURI
New Member
Apr 5, 2020

#3
  • 1

Rob your post is really good, in production environment I would like to backup all user’s history with time stamp from root. Till now i backup ~.bash_history file in user’s home directory…Please guide me if is it possible in linux…

Last edited: Apr 5, 2020
warlockk
warlockk
Active Member
Apr 5, 2020

#4

wizardfromoz said:
it may be worth noting for the viewers, rob, too, that if they spend a bit of time as root, they can likewise apply the above to the .bash_history that applies to root's activities.


avagudweegend

wizard
Click to expand...
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

you mentioned a useful point thanks wizardfromoz…

Like 
  • 1

Reactions: wizardfromoz

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/72898
推荐阅读
相关标签
  

闽ICP备14008679号