Append bash history in real-time and change output to show date and time of the command execution

Bash history can be very useful to re-trace steps performed on the system, but one of the issues is that commands are not logged in real-time but after ending a session. Also history output does not include date and time which is really useful for debugging.

In order to solve this you will need to append 3 lines to your ~/.bashrc file:

shopt -s histappend
PROMPT_COMMAND="history -a;$PROMPT_COMMAND"
export HISTTIMEFORMAT='%F %T '

In order for this to become active you need either to log out and log back in our execute:

source ~/.bashrc

After this all your commands will be logged in real-time and output of history command will have date & time information in following format:

YYYY-MM-DD HH:MM:SS history

Useful shell shortcuts

Here are some useful shell shortcuts that you can use to make your life easier:

CTRL+A - move to beginning of line
CTRL+E - move to the end of the line
CTRL+B - move backward
CTRL+F - move forward
CTRL+D - delete character under cursor
CTRL+K - deletes text from cursor to the end of line
CTRL+X+BACKSPACE - delete text from cursor to the beginning of the line
CTRL+T - exchange character under cursor with previous character
ESC+T - exchange two words before and under cursor
ESC+U - converts text from cursor to the end of the word to UPPERCASE
ESC+L - converts text from cursor to the end of the word to LOWERCASE
CTRL+X+CTRL+E - launch default editor
CTRL+L - Clears screen above current line
CTRL+W - Delete word from cursor position to the left
CTRL+R - Search through command history

Bash zip all files in directory one by one in individual zips

If you like me have for example folder filled with NES rom files that end with .nes extension and you would like to zip them all up in individual files to save some space.

I use this one-liner to zip all my NES collection so that it will take less space on my USB stick when I transfer it to my bartop arcade running RetroPie:

for file in *.nes ; do zip "$file.zip" "$file"; done

Continue reading “Bash zip all files in directory one by one in individual zips”