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]] | + | * [[HISTSIZE]] |
− | * | + | * 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> |
== Usage == | == Usage == | ||
− | * | + | * Basic example: |
− | :<code> | + | :<code>export PROMPT_COMMAND='history -a'</code> |
* Advanced examples: | * Advanced examples: | ||
− | ** <code>echo '[[export]] | + | **<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>[[set]] -o history</code> |
* <code>[[docker history]]</code> | * <code>[[docker history]]</code> | ||
− | |||
− | |||
== See also == | == See also == | ||
− | * | + | * <code>[[acct]]</code> |
− | * | + | * [[fc]] |
* {{Bash}} | * {{Bash}} | ||
Advertising: