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

vagrant@homestead:/$ b

vagrant@homestead:/$ c


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

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.