Linux Keyboard Tricks

Linux Keyboard Tricks

It’s helpful to learn a few Linux Keyboard Tricks. You may have noticed that when working with Linux at the command line, everything seems like a shortcut. In other words, instead of having descriptive commands such as list files, or change directory, we have things like ls and cd. What’s up with that? You might call it laziness, but really, its more of trying to get the most amount of work done with the fewest keystrokes. In this vein, there are a bunch of Linux keyboard tricks that we should know to help us along when making use of the command line. Let’s investigate this topic now.

Moving The Cursor At The Command Line

When at the command line, you are unable to use the mouse to move the cursor to different areas of text. At first this might seem like a hinderance, but there are plenty of tricks to allow you to move you cursor anywhere at will. These make use of the ALT key and the CTRL key. Here are a few options.

  • ALT-B This moves the cursor back by one word
  • ALT-F ALT-F sends the cursor forward by one word
  • CTRL-E CTRL-E allows you to jump all the way to the end of the line
  • CTRL-A CTRL-A moves the cursor to the start of a line
  • CTRL-F Works the same as the right arrow key
  • CTRL-B Works the same way as the left arrow key

Editing Text On The Command Line

It is also possible to edit text such as deleting, transposing, converting and so on. Let’s have a look at some of the various commands available.

  • CTRL-U Cuts the text from where the cursor is located to the beginning of the line.
  • CTRL-K Cuts the text from where the cursor is located to the end of the line.
  • ALT-D Cuts the text from where the cursor is located to the end of the current word.
  • ALT-backspace Cuts the text from the cursor location to the beginning of the word.
  • CTRL-Y yanks the text from the register and inserts it at the location of the cursor.

Auto Complete In Linux With The Tab Key

If it is not already, the tab key may become one of your best friends. This is because you can use tab to easily auto complete linux commands and other things when you’re not sure what they are for. Let’s test it out on a few commands.

vagrant@homestead:/$ a

a2p                           apparmor_status               apt-sortpkgs
aa-exec                       apport-bug                    ar
aa-status                     apport-cli                    arch
accessdb                      apport-collect                arp
aclocal                       apport-unpack                 arpd
aclocal-1.14                  apropos                       as
acpi_available                apt                           at
acpid                         apt-add-repository            atd
acpi_listen                   apt-cache                     atq
add-apt-repository            apt-cdrom                     atrm
addgroup                      apt-config                    autoconf
addpart                       apt-extracttemplates          autoheader
addr2line                     apt-ftparchive                autom4te
add-shell                     apt-get                       automake
adduser                       aptitude                      automake-1.14
agetty                        aptitude-create-state-bundle  autoreconf
alert                         aptitude-curses               autoscan
alias                         aptitude-run-state-bundle     autoupdate
apm_available                 apt-key                       awk
apparmor_parser               apt-mark                      axi-cache

vagrant@homestead:/$ b

badblocks                 bsd-write                 byobu-screen
base64                    builtin                   byobu-select-backend
basename                  bunzip2                   byobu-select-profile
bash                      busybox                   byobu-select-session
bashbug                   byobu                     byobu-shell
batch                     byobu-config              byobu-silent
bc                        byobu-ctrl-a              byobu-status
bdftopcf                  byobu-disable             byobu-status-detail
bdftruncate               byobu-disable-prompt      byobu-tmux
beanstalkd                byobu-enable              byobu-ugraph
bg                        byobu-enable-prompt       byobu-ulevel
bind                      byobu-export              bzcat
biosdecode                byobu-janitor             bzcmp
blackfire                 byobu-keybindings         bzdiff
blackfire-agent           byobu-launch              bzegrep
blkid                     byobu-launcher            bzexe
blkmapd                   byobu-launcher-install    bzfgrep
blockdev                  byobu-launcher-uninstall  bzgrep
bower                     byobu-layout              bzip2
break                     byobu-prompt              bzip2recover
bridge                    byobu-quiet               bzless
bsd-from                  byobu-reconnect-sockets   bzmore

vagrant@homestead:/$ c

Display all 100 possibilities? (y or n)


In this example we simply type the letter a and then the tab key twice and it lists all of the possible commands that begin with a. We do this again for the letter b, and then c, however since the letter c would return 100 results, we chose not to list them. Try it out for yourself in your terminal.

Using Clear and History

One thing you’ll notice while working at the command line, is that the terminal quickly fills up with a lot of information from past commands, output, and so on. Many times, you’ll want to get a nice clear screen to work with without having to close and re-open the terminal. Thankfully, there’s a way to get a fresh start with the clear command. In this snippet, we’ll take a look at the history of the commands we’ve been using, then get a fresh start with clear.

vagrant@homestead:~$ history

    1  clear
    2  ls
    3  php --version
    4  clear
    5  composer --version
    6  clear
    7  exit
    8  cd /
    9  l
   10  c
   11  a
   12  c
   13  history
   14  php --version
   15  composer --version
   16  c
   17  history
   18  ls
   19  cd
   20  top
   21  pstree
   22  c
   23  history
   24  ls -a .ba
   25  ls -a
   26  c
   27  history

vagrant@homestead:~$ clear

Linux Keyboard Tricks Summary

In reality, there are hundreds of tricks to use at the command line in Linux. We just took a look at a handful of useful ones here. Likely the most useful ones we’ll make use of are the tab for auto complete, history, and clear. One final helpful resource can be found at this handy cheat sheet if you’re interested.

Leave a Reply