Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

a shell builtin command in watch?

Status
Not open for further replies.

ogniemi

Technical User
Nov 7, 2003
1,041
PL

because I can't find any command replacement to the built-in 'history' command, I'd like to ask you if can use watch + history to continuously view history changes with date:

root@test:~# history|tail -2
598 17/11/15 14:23:48 :: HISTTIMEFORMAT="%d/%m/%y %T :: "
599 17/11/15 14:23:54 :: history|tail -2

what I tried to do is:

# watch -t -d=cumulative history

but it fails with error:

sh: 1: history: not found

anyway to use history with watch comamnd?

 
If you want to just get commands that end up in the history, with time stamp, as they happen, this should get you close...

Code:
tail -f ~/.sh_history | (unset IFS; while read LINE; do print "$(date '+%Y%m%d:%H%M%S'): ${LINE}"; done)

Output looks like this...

Code:
20151117:110700: ls -la
20151117:110941: man history
20151117:110948: ls -la
20151117:111013: find . -name '*.sql' -ls

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top