Some Shell Shortcuts

The following describes some common and useful “Shell” (/bin/sh) or “Bash” (/bin/bash) Unix and Linux command-line ‘shell’ key based shortcuts for commands or actions:

a) CTRL-a brings the cursor to the start of the current line and CTRL-e puts it to the end of the current line

b) CTRL-z will “suspend” the current running command and return you to the shell prompt, where if you then type “bg” & enter, that command will be allowed to run again, but be “in the background” and you’ll be back at the shell prompt. Type “jobs” to see the still running backgrounded command and “fg” to return to it.

c) CTRL-w will delete the word _behind_ the current cursor position & CTRL-u will delete the whole line behind the current cursor position

d) CTRL-k will delete the rest of the line after the current cursor position

e) CTRL-l will clear the current shell screen/window, same as the “clear” command

f) The “reset” command in a shell will clear the screen and ‘reset’ the shell’s character-set and other settings (useful if the screen gets binary chars output on it)

g) !! (“bang bang”) on a command-line will re-run the previous command

h) !* (“bang star”) on a command-line will include “the previous command line EXCEPT its last parameter”) at the place where the !* chars are located in the current command-line

i) !$ (“bang dollar”) used on a command-line will include the “last parameter of the previous command line” at the place where the !$ chars are located in the current command-line
Eg: if the previous command was: ls –l /a/directory/path/here then !$ on the next command-line will be “/a/directory/path/here” and you could easily cd to that dir with: cd !$

j) Adding the chars “:p” to the !* or !$ commands will just print what they’d insert, not actually insert those chars, but will put them into the history list

k) You can change text in the previous command line with the ‘^text-to-change^replacement-text^’ character sequence at the start of a new command-line
Eg: If the previous command had a typo like: ls –latr /a/directory/pathhereismissingsome/
And you want to add some missed ‘/’ char after the ‘path’ directory name, start the next command line with ^path^path/^ and the command-line executed will be: ls –latr /a/directory/path/hereismissingsome/

There’s lots of pages on these shortcuts, here’s a useful one from a useful site:
http://www.techrepublic.com/article/master-the-linux-bash-command-line-with-these-10-shortcuts/5827311

FYI,
Richard.

This entry was posted in Network Presence, Rich and tagged . Bookmark the permalink.