赞
踩
Thread starter Rob Start date Mar 7, 2020
Tags
bash history history
Rob
Rob
Administrator
Staff member
Mar 7, 2020
#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
Reactions: Karthick and wizardfromoz
wizardfromoz
wizardfromoz
Super Moderator
Staff member
Gold Supporter
Mar 7, 2020
#2
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
Reactions: Ca8aB and Rob
NIMMAKURI
New Member
Apr 5, 2020
#3
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...
you mentioned a useful point thanks wizardfromoz…
Like
Reactions: wizardfromoz
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。