$ mysql –version
mysql Ver 14.14 Distrib 5.1.37, for debian-linux-gnu (i486) using EditLine wrapper
- vi-mode is not working
- emacs mode is not full supported
To solve this problem use the following trick:
Install rlwrap:
sudo apt-get install rlwrap
Set a alias in your profile/bashrc
alias mysql='rlwrap -a mysql'
All readline features should now work again... Happy mysqlvimming :)
Bash, Development
Bash, mysql
- Copy Monaco.dfont from /System/Library/Fonts on your Mac to your Linux box in your ~/.fonts directory
- Run fc-cache to reload the fontconfig cache
- Set hte new font in your application (Terminal, GVim, Gedit,…)
Apple, Bash, Config
Apple, gvim, Linux, MacOSX
History Expansion
Moving in the History File
emacs Mode
| Command |
Description |
| CTRL-P |
Move to previous line |
| CTRL-N |
Move to next line |
| CTRL-R |
Search backward |
| ESC-< |
Move to first line of history file |
| ESC-> |
Move to last line of history file |
vi Mode
| Command |
Description |
| k or - |
Move backward on line |
| j or + |
Move forward one line |
| G |
Move to line given by repeat count |
| /string |
Search backward for string |
| ?string |
Search forward for string |
| n |
Repeat search in same direction as previous |
| N |
Repeat search in opposite direction of previous |
Event Designators
| Command |
Description |
| ! |
Start a history substitution |
| !! |
Refers to the last command |
| !n |
Refers to command line n |
| !-n |
Refers to current command line minus n |
| !string |
Refers to the most recent command starting with string |
| !?string? |
Refers to the most recent command containing string. The ending ? is optional |
| ^string1^string2 |
Repeat the last command, replacing string1 with string2 |
Word Designators
| Designator |
Description |
| 0 |
The zeroth (first) word in a line |
| n |
The nth word in a line |
| ^ |
The first argument (the second word) |
| $ |
The last argument in a line |
| % |
The word matched by the most recent ?string search |
| x-y |
A range of words from x to y. -y is synonymous with 0-y |
| * |
All words but the zeroth (first). Synonymous with 1-$. If there is only one word on the line, an empty string is returned. |
| x* |
Synonymous with x-$ |
| x- |
The words form x to the second last word |
The word designator follows the event designator, separated by a colon. You could repeat the previous command with different arguments by typing !!:0 followed by the new arguments.
Event designators may also be followed by modifiers.
Modifiers
| Modifier |
Description |
| h |
Removes a trailing pathname component, leaving the head |
| r |
Removes a trailing suffix on the from.xxx |
| e |
Removes all but the trailing suffix |
| t |
removes all leading pathname components, leaving the tail |
| p |
Prints the resulting command but doesn’t execute it |
| q |
Quote the substituted words, escaping further substitutions |
| x |
Quote the substituted words, breaking them into words at blanks and newlines |
| s/old/new/ |
Substitutes new for old |
More than one modifier can bey separated by a colon.
Environment Variables
| Command |
Description |
| HISTCMD |
The history number of the current command. |
| HISTCONTROL |
Controls what is entered in the command history. |
| HISTFILE |
The name of the command history file. (~/share.webdav/.history, Same history on different machines) |
| HISTIGNORE |
A list of patterns to decide what should be retained in the history list. Using a space before a command always ignore it for the history. |
| HISTSIZE |
The number of lines kept in the command history. |
| HISTFILESIZE |
The maximum number of lines kept in the history file. |
| HISTTIMEFORMAT |
Command line history with timestamp, supports format strings of strftime. (‘%F %T) |
shopt Options
The shopt options are set with shopt -sarg and unset with shopt -uarg.
| Option |
Description |
| cmdhist |
Attempt to save all lines of multiline command in a single history entry. |
| histreedit |
If readline is being used, the opportunity is given for re-editing a failed history substitution. |
| histverify |
If readline is being used, the reults of history substituion are not immediately passed to the shell parser. Instead, the resulting line is loaded into the readline editing buffer, allowing further modification. |
| lithist |
If the cmdhist option is enabled, multiline commands are saved to the history with embedded newlines rather than using semicolon seperators where possible. |
Useful Articles:
15 Examples To Master Linux Command Line History
More text is coming…
Bash
Bash
| Redirector |
Function |
| cmd1 | cmd2 |
Pipe; take standard output of cmd1 as standard input to cmd2 |
| > file |
Direct standard output to file |
| < file |
Take standard input from file |
| >> file |
Direct standard output to file; append to file if it already exists |
| >| file |
Force standard output to file even if noclobber is set |
| n>| file |
Force output to file from file descriptor |
| n |
even if noclobber set |
| <> file |
Use file as both standard input and standard output |
| n<> file |
Use file as both input and output for the file descriptor n |
| << label |
Here-document |
| n> file |
Direct file descriptor n to file |
| n< file |
Take file descriptor n from file |
| >> file |
Direct file descriptor n to file; append to file if it already exists |
| n>& |
Duplicate standard output to file descriptor n |
| n<& |
Duplicate standard input from file descriptor n |
| n>&m |
File descriptor n is made to be a copy of the output file descriptor |
| n<&m |
File descriptor n is made to be a copy of the input file descriptor |
| &> file |
Directs standard output and standard error to file |
| <&- |
Close the standard input |
| >&- |
Close the standard output |
| n>&- |
Close the output from file descriptor n |
| n<&- |
Close the input from file descriptor n |
Useful Articles:
Redirection (Wikipedia)
Bash
Bash
Here is a complete list of all vi control mode commands for bash.
| Command |
Meaning |
| ESC |
Switch to command mode. |
| h |
Move left one character |
| l |
Move right one character |
| w |
Move right one word |
| b |
Move left one word |
| W |
Move to beginning of next non-blank word |
| B |
Move to beginning of preceding non-blank word |
| e |
Move to end of current word |
| E |
Move to end of current non-blank word |
| 0 |
Move to beginning of line |
| ^ |
Move to first non-blank character in line |
| $ |
Move to end of line |
| % |
Move to the corresponding opening/closing bracket. |
| i |
Insert text before current character |
| a |
Insert text after current character |
| I |
Insert text at beginning of line |
| A |
Insert text at end of line |
| R |
Overwrite existing text |
| r |
Replaces a single character under the cursor (without leaving command mode). |
| dh |
Delete one character backward |
| dl |
Delete on character forward |
| db |
Delete on word backward |
| dw |
Delete on word forward |
| dB |
Delete one non-blank word backward |
| dW |
Delete one non-blank word forward |
| d$ |
Delete to end of line |
| d0 |
Delete to beginning of line |
| D |
Equivalent to $d (delete to end of line) |
| dd |
Equivalent to 0d$ (delete entire line) |
| C |
Equivalent to c$ (delete to end of line, enter input mode) |
| cc or S |
Equivalent to 0c$ (delete entire line, enter input mode) |
| s |
Delete a single character under the cursor and enter input mode (equivalent to c[SPACE]). |
| x |
Equivalent to dl (delete character forwards) |
| X |
Equivalent to dh (delete character backwards) |
| u |
Undo previous text modification. |
| U |
Undo all previous text modifications. |
| . |
Redo the last text modification. |
| y |
Yank a movement into buffer (copy). |
| yy |
Yank the whole line. |
| p |
Insert the yanked text at the cursor. |
| P |
Insert the yanked text before the cursor. |
| k or - |
Move backward one line |
| j or + |
Move forward one line |
| G |
Move to line given by repeat count |
| /string |
Search forward for string |
| ?string |
Search backward for string |
| n |
Repeat search forward |
| N |
Repeat search backward |
| fx |
Move right to next occurrence of x |
| Fx |
Move left to previous occurrence of x |
| tx |
Move right to next occurrence of x, then back one space |
| Tx |
Move left to previous occurrence of x, then forward one space |
| ; |
Redo last character finding command |
| , |
Redo last character finding command in opposite direction |
| \ |
Do filename completion |
| * |
Do wildcard expansion (onto command line) |
| \= |
Do wildcard expansion (as printed list) |
| ~ |
Invert (twiddle) case of current character(s) |
| \_ |
Append last word of previous command, enter input mode |
| CTRL-L |
Start a new line and redraw the current line on it |
| # |
Prepend # (command character) to the line and send it to history |
| v |
Edit and execute the current command in the text editor. (an editor defined in $VISUAL or $EDITOR variables, or vi) |
Bash
Bash