Editing Bash history

Jump to navigation Jump to search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 2: Line 2:
  
 
Variables to control Bash History:
 
Variables to control Bash History:
* [[HISTSIZE]] (<code>[[echo]] $HISTSIZE</code>)
+
* [[HISTSIZE]]
* [[HISTFILE]]<ref><https://www.gnu.org/software/bash/manual/bash.html#index-HISTFILE</ref>: The default value is <code>~/[[.bash_history]]</code>
+
* HISTFILE<ref><https://www.gnu.org/software/bash/manual/bash.html#index-HISTFILE</ref>: The default value is <code>~/[[.bash_history]]</code>
 
* HISTFILESIZE
 
* HISTFILESIZE
* [[HISTTIMEFORMAT]] <ref>https://www.gnu.org/software/bash/manual/bash.html#index-HISTTIMEFORMAT</ref>
+
* HISTTIMEFORMAT<ref>https://www.gnu.org/software/bash/manual/bash.html#index-HISTTIMEFORMAT</ref>
  
 
== Usage ==
 
== Usage ==
* Save every executed command to: <code>[[~/.bash_history]]</code>
+
* Basic example:
:<code>[[export]] [[PROMPT_COMMAND]]='[[history -a]]'</code>
+
:<code>export PROMPT_COMMAND='history -a'</code>
 
* Advanced examples:  
 
* Advanced examples:  
** <code>echo '[[export]] [[HISTTIMEFORMAT]]="%d/%m/%y %T "' >> ~/.[[bash_profile]]</code><ref>https://www.cyberciti.biz/faq/unix-linux-bash-history-display-date-time/</ref>
+
**<code>echo '[[export]] HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.[[bash_profile]]</code><ref>https://www.cyberciti.biz/faq/unix-linux-bash-history-display-date-time/</ref>
 
**<code>export [[PROMPT_COMMAND]]='if [ "$(id -u)" -ne 0 ]; then echo "$(date "+%Y-%m-%d.%H:%M:%S") $(pwd) $(history 1)" >> ~/.logs/bash-history-$(date "+%Y-%m-%d").log; fi'</code><ref>https://gist.github.com/NISH1001/bf2b713418b4e2ede8e6a7373b42c4c1</ref>
 
**<code>export [[PROMPT_COMMAND]]='if [ "$(id -u)" -ne 0 ]; then echo "$(date "+%Y-%m-%d.%H:%M:%S") $(pwd) $(history 1)" >> ~/.logs/bash-history-$(date "+%Y-%m-%d").log; fi'</code><ref>https://gist.github.com/NISH1001/bf2b713418b4e2ede8e6a7373b42c4c1</ref>
 
**Sending history to syslog (needs recompiling source): Bash also support syslog capabilities at compiling time<ref>https://unix.stackexchange.com/questions/457107/sending-bash-history-to-syslog</ref> but it is not enabled by default in most distributions: https://github.com/bminor/bash/blob/d233b485e83c3a784b803fb894280773f16f2deb/config-top.h
 
**Sending history to syslog (needs recompiling source): Bash also support syslog capabilities at compiling time<ref>https://unix.stackexchange.com/questions/457107/sending-bash-history-to-syslog</ref> but it is not enabled by default in most distributions: https://github.com/bminor/bash/blob/d233b485e83c3a784b803fb894280773f16f2deb/config-top.h
Line 20: Line 20:
  
 
== Other terms  ==
 
== Other terms  ==
* <code>[[set -o history]]</code>
+
* <code>[[set]] -o history</code>
 
* <code>[[docker history]]</code>
 
* <code>[[docker history]]</code>
* <code>[[history --help]]</code>
 
* <code>[[histappend]]</code>
 
  
 
== See also ==
 
== See also ==
* {{acct}}
+
* <code>[[acct]]</code>
* {{history}}
+
* [[fc]]
 
* {{Bash}}
 
* {{Bash}}
  

Please note that all contributions to wikieduonline may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see Wikieduonline:Copyrights for details). Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)

Advertising: