Difference between revisions of "Bash history"
Jump to navigation
Jump to search
Line 10: | Line 10: | ||
:<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 |
Revision as of 08:47, 18 December 2019
Bash Command history feature allows to recall, edit and rerun previous commands. Also allows commands to be saved using the history -a
command[1][2].
Variables to control Bash History:
Usage
- Basic example:
export PROMPT_COMMAND='history -a'
- Advanced examples:
echo 'export HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bash_profile
[5]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'
[6]- Sending history to syslog (needs recompiling source): Bash also support syslog capabilities at compiling time[7] but it is not enabled by default in most distributions: https://github.com/bminor/bash/blob/d233b485e83c3a784b803fb894280773f16f2deb/config-top.h
Activities
- Install https://github.com/ohmybash bash customization
See also
Source: https://en.wikiversity.org/wiki/Bash_programming/Bash_History
- ↑ https://unix.stackexchange.com/questions/145250/where-is-bashs-history-stored
- ↑ https://www.gnu.org/software/bash/manual/bash.html#Bash-History-Builtins
- ↑ <https://www.gnu.org/software/bash/manual/bash.html#index-HISTFILE
- ↑ https://www.gnu.org/software/bash/manual/bash.html#index-HISTTIMEFORMAT
- ↑ https://www.cyberciti.biz/faq/unix-linux-bash-history-display-date-time/
- ↑ https://gist.github.com/NISH1001/bf2b713418b4e2ede8e6a7373b42c4c1
- ↑ https://unix.stackexchange.com/questions/457107/sending-bash-history-to-syslog
Advertising: