The next class of shortcuts we want to discuss is keyboard shortcuts. In contrast to the previous commands and shell keywords, these are simply key combinations that modify things on the command line. The combinations we're discussing all work by using the CTRL key as a modifier: you hold down CTRL and press another key, for example the t. We'll describe this as CTRL+t, as we have done in the rest of the book as well. Speaking of CTRL+t, this is actually the first shortcut we'd like to address! You can use CTRL+t when you've made a typo:
reader@ubuntu:~$ head /etc/passdw
# Last two letters are swapped, press CTRL+t to swap them:
reader@ubuntu:~$ head /etc/passwd
Because the terminal is modified, it is kind of hard to get an accurate representation for these pages. We've included a comment between the lines, to show what we do and what changes when we do it. However, in your Terminal, you will only ever see one line. Go ahead and try it out. By pressing CTRL+t, you can swap the last two characters around as often as you'd like. Do note that it takes whitespace into account as well: if you've already pressed the spacebar, you'll swap the whitespace with the last letter, like so:
reader@ubuntu:~$ sl
# CTRL+t
reader@ubuntu:~$ s l
If you start using this shortcut, you will soon realize that swapping two letters is a much more common occurrence than you might initially expect. As with most things in Bash, this functionality is present because people use it, so you do not need to feel bad about yourself if this happens to you a bit too often! At least with this shortcut, you'll be able to mitigate the errors quickly.
Next up is the CTRL+l shortcut (lowercase L), which is actually a shortcut for a command: clear. The functionality of clear is almost as simple as the name of the command: clear - clear the terminal screen (from man clear). This is actually a shortcut (and by extension, a command) that we use extensively for every Terminal session. As soon as you get to the bottom of your Terminal emulator screen, with a lot of clutter above, you might notice this isn't as nice to work with as the empty Terminal you start with (our personal opinion, perhaps shared by you). If you want to clear this up, you can either use the CTRL+l shortcut, or simply type the command clear. When you clear your Terminal, the output is not gone: you can always scroll up (often via mouse wheel or SHIFT+page-up) to see what was cleared. But at least your cursor is on a nice, clean screen at the top!
There is also a shortcut for the exit command, CTRL+d. Not only does this work great for when you want to exit an SSH session, but it works for many other interactive prompts as well: a great example for this is at (in reality, you need to use CTRL+d to exit from the at prompt, as exit will just be interpreted as a command to run!). As you know, CTRL+c sends a cancel to a running command (technically a SIGINT, as there are many intensities of cancel/kill under Linux), so be sure not to confuse CTRL+d with CTRL+c.
With regards to navigation, there are two CTRL-based shortcuts which are often easier to reach than their alternatives: CTRL+e and CTRL+a. CTRL+e moves the cursor to the end of the line, in a similar way to what the END key accomplishes. As you might expect, CTRL+a does the reverse: it functions as an alternative to the HOME key. Especially for those of you that are proficient in touch typing, these shortcuts are faster than moving your right hand away from the home row to find the END/HOME keys.