Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Save all of your Terminal activity to a file' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Save all of your Terminal activity to a file
Authored by: excarnate on May 11, '12 10:44:39AM

Actually you can save your history from multiple windows to a single .bash_history file. Here are some things related to history in my .bash_profile:

HISTSIZE=2222
HISTFILESIZE=999999
HISTTIMEFORMAT="%Y%m%d-%T "
HISTIGNORE="&:pwd:ls:[bf]g:exit:[ \t]*"
shopt -s cmdhist
shopt -s histappend
export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"
function hs {
grep $1 $HISTFILE
}

In order, this:
Sets the history kept for a current iteration of the shell to larger than the default of 500. If you have a lot of terminal sessions or keep them open for weeks/months you may want to up this value.
Keeps a large history file (which I like, this may be a bit much, though).
Records and displays the date and time of a command.
Ignores repeated and uninteresting commands, also allows you to keep a command out of history by starting it with a space or a tab.
Displays multiple commands entered on a single line on a single line (think: for loop). This is just my preference.
Appends history from all windows.
Everytime there is a new prompt, the history is appended, cleared, read (back) in so history from all windows is available and displays correctly in all windows.
Finally, a command to search the history (e.g. an easier way than history|grep foo).

This doesn't record, as 'script' does, the output of commands, but it does much of what is useful (I use the script command in more limited circumstances). If you don't use (the default) bash shell, you'll have to look up how to do things in your chosen shell.

Note that the script command records control characters like backspaces, and capturing a vi session is a bit messy. If just want a history of what you typed, use the built in history functionality of bash.

Edited on May 11, '12 12:13:37PM by excarnate



[ Reply to This | # ]
Save all of your Terminal activity to a file
Authored by: excarnate on May 11, '12 11:58:58AM

<deleted, redundant>

Edited on May 11, '12 12:14:04PM by excarnate



[ Reply to This | # ]