Saturday, July 7, 2007

Command line tips

One of the things I like the most on the Mac is I can open terminal and
play at the command line. I seem to spend about 40% of my time on the
command line.

As you are typing a (lengthy) command, you may find a need to go back and
change it. You can use the left and right arrow to move one character at a time, but that's painful.

You can quickly navigate through that line of command by using some shortcuts.
ctrl-a takes you to the beginning of the line.
ctrl-e takes you to the end of the line
ctrl-w eats the word to the left
ctrl-h eats the character to the left
ctrl-d eats the current character
ctrl-k eats everything to the right of cursor

When I make presentations I find two other tricks very useful.
I often want to clear the screen.
ctrl-L clears the screen. You can type it even when you're in the middle of typing commands.
ctrl-+ will increase the font size (need to hold shift to reach the +).
ctrl-- will decrese the fond size.

5 comments:

Unknown said...

You missed
ctrl + r = reverse-i-search, use it before typing a command and it searches for matches in your history
cmd + k = which removes all the text from the console

Jeffrey Fredrick said...

ctrl+r is huge, use it all the time.

Derek said...

To increase/reduce font size, you use cmd instead of ctrl:

cmd +
cmd -

Edward said...

You might also want to consider putting the following in ~/.inputrc to fix a few things that the default Mac terminal seems to break:

######################
######################
# From http://tech.inhelsinki.nl/gnu_developement_under_mac_os_x/
#
# Be 8 bit clean.
set input-meta on
set output-meta on
set convert-meta off

# do not bell on tab-completion
set bell-style none

# allow the use of the Home/End keys
"\e[1~": beginning-of-line
"\e[4~": end-of-line

# allow the use of the Delete/Insert keys
"\e[3~": delete-char
"\e[2~": quoted-insert

# mappings for "page up" and "page down" to step to the beginning/end
# of the history
"\e[5~": beginning-of-history
"\e[6~": end-of-history

# alternate mappings for "page up" and "page down" to search the history
# "\e[5~": history-search-backward
# "\e[6~": history-search-forward

# aterm / eterm (control + arrow key)
"\e[5C": forward-word
"\e[5D": backward-word
######################
######################

Additionally, I recommend sticking the following in
The following also needs to go into ~/Library/KeyBindings/DefaultKeyBinding.dict

{
/* Changes home/end keys to a sane behaviour */
"\UF729" = "moveToBeginningOfLine:"; /* home */
"\UF72B" = "moveToEndOfLine:"; /* end */
"$\UF729" = "moveToBeginningOfLineAndModifySelection:"; /* shift + home */
"$\UF72B" = "moveToEndOfLineAndModifySelection:"; /* shift + end */

/* Changes pgup/pgdn keys to sane behaviour */
"\UF72C" = "pageUp:"; /* pgup */
"\UF72D" = "pageDown:"; /* pgdn */
"$\UF72C" = "pageUpAndModifySelection:"; /* shift + pgup */
"$\UF72D" = "pageDownAndModifySelection:"; /* shift + pgdn */
}set completion-ignore-case On

Kaleb S said...

Hi, nice reading your post