Speeding up work at Linux command line part # 1

by nixcraft on August 29, 2005 · 2 comments

Working at shell prompt is an essential task for any Linux system administration. However many newcomers find it difficult to work at bash prompt. Here are some tricks to speed up your work.

(A) Shortcut keys for command editing:
CTRL+L : Clear the screen

CTRL+R : To search for a command in command history. For example yesterday or few hourse back you typed 'a very very long command' and you need same command again. Then hit CTRL+R and type first few letters of command.

CTRL+C : Cancel command

CTRL+Z : Suspend command

CTRL+T : transpose characters. For example by misspelled command date:
$ daet
Sure you can rub the last two character and retype it again, but wait just hist CTRL+T and you are done:
$ daet [CTRL+T]
Result into character transpose:
$ date

ALT+T OR ESC+T: transpose words. For example you typed:
$ filename rm
To correct it just hit ALT+T
$ filename rm [ALT+T]
And you have correct command to remove a file.
$ rm filename

CTRL+U : Deletes entire line

CTRL+K : Deletes to end of line from current cursor position

HOME OR CTRL+A : Moves cursor to beginning of line

END OR CTRL+E : Moves cursor to end of line

(B)Recall last argument from previous command – to save time
ALT+. (hold down ALT key and press period/dot)
For example first you typed the mkdir command as follows:
$ mkdir -p /tmp/demo/software/qtapp
Now you would like change directory to /tmp/demo/software/qtapp, then type cd and press ALT+.:
$ cd [PRESS alt+.]

(C) Command completion
Most of the Linux admin uses TAB key to complete command names and files names. So let us say you would like to mount something then:
i) Type word mo:
$ mo
ii) Hit TAB key to complete word
$ mo [TAB]
iii) And end result should be:
$ mount

(D) List the possible completions
BASH also supports the possible completions of commands or text (file). For example you would like to list all the possible command starts with ls command:
$ ls [ESC]
Will display following text (above the current command line)

ls lsmod lsmod.modutils lspci lsusb
lsattr lsmod.Lmodutils lsof

Next time I will discuss more about advanced command line completions and other cool features.

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

We're here to help you make the most of sysadmin work. So, subscribe!

{ 2 comments… read them below or add one }

1 Anonymous August 31, 2005

Hmm that is cool, you can also read more shortcut keys in bash man page.

Reply

2 Philippe Petrinko May 10, 2010

A thing to amend:
“CTRL-U : Deletes entire line”

No, CTRL-U Deletes from current cursor position to beginning of line (the opposite of CTRL-K)

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 14 + 13 ?
Please leave these two fields as-is:
Are you a human being? Solve the simple math so we know that you are a human and not a bot.



Previous post:

Next post: