obda.net

Zsh History Expansion

1 comment

cheat-sheet articles are about code snippets that I need every once in a while, and which I constantly forget about.

Shortcut Description
!! the entire previous command
!!^ the first argument from the previous command
!!* all arguments from the previous command
!!:n the n-th word from the previous command
!!$ the last word from the previous command
!# the entire current command line (typed in so far)
!#^ the first argument from the current command line
!#* all arguments from the current command line
!#:n the n-th word from the current command line
!#$ the last word from the current command line

For more information, read Andrew Grangaard’s Zsh history expansion article.

Zsh Line Editor Shortcuts

Add a comment

cheat-sheet articles are about code snippets that I need every once in a while, and which I constantly forget about.

Note: These shortcuts are valid for Zsh’s emacs mode, not necessarily for vi mode.

Shortcut Description
M-. insert the last word from the previous history entry1
C-u kill the current line
C-v C-j insert newline at current cursor position
C-x C-e edit current command line in $EDITOR
C-x C-f char move to the next occurrence of character char

  1. press M-. repeatedly to get the last words from older history entries 

Delete MySQL Binary Logs

Add a comment

cheat-sheet articles are about code snippets that I need every once in a while, and which I constantly forget about.

From the MySQL manual:

The binary log contains “events” that describe database changes such as table creation operations or changes to table data. It also contains events for statements that potentially could have made changes (for example, a DELETE which matched no rows), unless row-based logging is used. The binary log also contains information about how long each statement took that updated data.

The binary log is primarily needed for master-slave-setups and data recovery operations. Files are never deleted and pile up in the datadir (e.g. /var/lib/mysql), named mysqld-bin.000001, mysqld-bin.000002, … (Alternatively, the files might be named hostname-bin.000001, …)

To get rid of them, run the following two commands as MySQL’s admin user:

mysql> FLUSH LOGS;
mysql> RESET MASTER;

The first command flushes unsaved transactions to the database, and the second one deletes all binary logs.

If you do not need the binary logs at all, you can also disable them entirely by removing the log-bin option from your my.cnf configuration file.