-
-
Save cdcarson/5929167 to your computer and use it in GitHub Desktop.
Ctrl + A Go to the beginning of the line you are currently typing on | |
Ctrl + E Go to the end of the line you are currently typing on | |
Ctrl + L Clears the Screen, similar to the clear command | |
Ctrl + U Clears the line before the cursor position. If you are at the end of the line, clears the entire line. | |
Ctrl + H Same as backspace | |
Ctrl + R Let’s you search through previously used commands | |
Ctrl + C Kill whatever you are running | |
Ctrl + D Exit the current shell | |
Ctrl + Z Puts whatever you are running into a suspended background process. fg restores it. | |
Ctrl + W Delete the word before the cursor | |
Ctrl + K Clear the line after the cursor | |
Ctrl + T Swap the last two characters before the cursor | |
Esc + T Swap the last two words before the cursor |
Oh, also, ctrl-D... that works by sending the EOF character which signifies end of input. This is useful not only for when you're in a shell, but for anything that's waiting on input, be it an interactive database session (mysql
or psql
), or a cat
command. It's friendlier than a ctrl-C since that sends an interrupt signal.
An example of the cat
thing above:
cat > some_file
you can then type some stuff in, press enter, type more, press enter... type some more, press enter... seems like it's doing nothing... type a ctrl-D and you're brought back to your prompt. Now look at the contents of some_file
and it'll contain everything you just typed. If you ctrl-C, it'll do the same, but only because that's how the cat
command is written (it outputs data each time it gets a line), but if it were to buffer everything and only write once input is completed, ctrl-C would completely terminate the action and nothing would occur. When you pipe the output of a command into another, when the first command finishes, it sends the EOF to signal the next process that it's done. ctrl-D is a way for you, the operator, to do this manually.
A note about ctrl-U,K,W:
This doesn't just delete the string, it puts it into a buffer in this shell's session. It can be recalled by typing a ctrl-Y.
this is really handy for when you're typing out a complex command, realize right before running it or halfway through that you want to do something else, you can ctrl-U, do some other stuff, then hit ctrl-Y to spit it back and do it. Saves the time of selecting the text with the mouse and copying it.
I use that all the time.
For ctrl-Z,
fg
restores the last backgrounded process of that session, which is usually the process you ctrl-z'd. You can use thejobs
command to see what backgrounded processes there are, which will not only list ctrl-z'd processes, but also processes launched in the background, for example viasome_longrunning_script.rb &
. You can then passfg
a parameter to choose which process to reattach to. You can also kill the processes using their index (the[1]
, for example) if you prefix it with a%
. Like:kill %1
.see
man jobs
for more info on that.