Speeding up work at Linux command line part # 1

by nixcraft [Last updated: August 29, 2005]

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.

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 1 comment… read it below or add one }

1 Anonymous 08.31.05 at 1:39 pm

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

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Previous post: xrandr: Linux resize screen size quickly

Next post: HP-UX networking related tools and commands