close
close

These Linux command line shortcuts will increase your efficiency

These Linux command line shortcuts will increase your efficiency

  • Use keyboard shortcuts for quick editing, moving, and searching to improve command line efficiency.

  • Enable the cd command with shortcuts like cd ~ and cd – to navigate the file system.

  • Use tab termination to reduce typing errors and increase speed when working with filenames and directories.

Typing commands in a Linux terminal window can be slow and error-prone. Use these keyboard shortcuts and other command-line tricks to improve efficiency and accuracy, and avoid frustration and errors.

How these shortcuts can help

The Linux command line gives you a lot of power. You get unparalleled access to the inner workings of your Linux installation. All Linux commands, configuration files and other tools at your disposal. But the command line’s defining characteristic is its biggest drawback: commands must be typed.

Text input is relatively slow. It’s also easy to make mistakes, especially when you type unfamiliar words, e.g cifsiostat. There is a danger associated with the wrong set of things on computers Linux is no different.

But even if your typo doesn’t result in data loss or other dramatic consequences, the repetition and annoyance of controlling your computer with the word you type can sap your enthusiasm for what you’re trying to do.

These tips, hints and tips will improve your accuracy and speed up your workflow.

Search your team history

Most people know that you can use the command to repeat command history function of your shell. All the commands you issue are stored in the list. The history command shows you a list. Enter an exclamation point to play the command! immediately followed by the command number, and then press Enter.

Well, show the history list, then repeat command number six.

history
!6
Displaying the history list and playing command number six.Displaying the history list and playing command number six.

Displaying the history list and playing command number six.

You can also use the up and down arrow keys to move between commands in the history list. When you see the command you want to execute, press Enter.

With a very long history list, it’s faster and easier to use Ctrl+R to search through command history.

Press Ctrl+R to start the search, then type a few characters of the command you want to repeat. The last executed corresponding command is displayed.

In this example, I pressed Ctrl+R and then typed “ls”, meaning “ls” and a space.

ls 
Using the Ctrl+r function to search the command history list.Using the Ctrl+r function to search the command history list.

Using the Ctrl+r function to search the command history list.

The characters you type appear before the colon “:” so you can see the search hint. You can continue to type characters to refine your search or press Enter to execute the displayed command.

The command found by searching with Ctrl+r is executed by pressing the Enter key.A command found by searching with Ctrl+r is executed by pressing the Enter key.

A command found by searching with Ctrl+r is executed by pressing the Enter key.

Esc returns without executing the command. This is a good way to get the command on the command line so you can edit it.

A command found by searching with Ctrl+r can be left on the command line ready for editing by pressing Esc.A command found by searching with Ctrl+r can be left on the command line ready for editing by pressing Esc.

A command found by searching with Ctrl+r can be left on the command line ready for editing by pressing Esc.

Quick command line editing

You probably already know Home, End, LeftArrow and RightArrow keys move the cursor over the text in the command line. Ctrl+Left Arrow and Ctrl+Right Arrow move the cursor from word to word.

The Backspace and Delete keys erase text one character at a time, but there are faster ways to delete parts of the command line you don’t need.

  • Ctrl+U deletes from the cursor position to the beginning of the line.

  • Ctrl+K deletes from the cursor position to the end of the line.

  • Home, Ctrl+U or Ctrl+U, Ctrl+K deletes the entire line.

  • Ctrl+W deletes the word to the left of the cursor.

  • Alt+D deletes the word to the right of the cursor.

  • Ctrl+Y inserts the deleted word at the cursor position. Temporary storage for words deleted with Ctrl+W and Alt+D does not affect the system clipboard.

Cut and paste on the command line

If you want to interact with the system clipboard using the command line, you can do so using keyboard shortcuts. They are similar to the well-known keyboard shortcuts Ctrl+C, Ctrl+V, but you need to use Shift at the same time.

CD-ROM activation

Using the command line means moving around your file system. The cd command moves you to another directory. There are also handy shortcuts to return you to your home directory.

cd ~and compact disc itself returns to the home directory from anywhere on the file system.

It’s pretty neat, but I find cd – more useful cd with option – takes you back to your previous catalog You can use it repeatedly to switch back and forth between the two directories.

cd ~/Downloads/taf
cd
cd -
cd -
Switch between the last two directories visited using cd -.Switch between the last two directories visited using cd -.

Switch between the last two directories visited using cd -.

The name of the directory you return to is printed in the terminal window.

Termination of tabs

You get a serious boost in speed and accuracy when using it Termination of tabs. This completely eliminates the possibility of typing errors when working with filenames, directory paths, and other system values.

The technique is the same in all cases. You type a small part of the directory path and then press Tab. The shell attempts to complete the rest of the filename, directory path, or command.

If there are several possible matches, you will hear a beep. Press Tab again and you will see possible matches. You need to enter enough characters to avoid ambiguity.

Here is an example. I typed “cd Do” and hit Tab. I heard a beep, so I pressed Tab again.

If the Tab completion finds more than one potential match, they are displayed if the user presses Tab again.If the Tab completion finds more than one potential match, they are displayed if the user presses Tab again.

If the Tab completion finds more than one potential match, they are displayed if the user presses Tab again.

Bash lists the appropriate directories and then resumes my half-finished command line. In this case, I only need to type the next letter to distinguish between the two directory names. “n” or “w” exactly identifies the directory I mean.

I typed “w” because I’m going to go to the downloads directory.

You only need to enter enough characters to distinguish between potential matches.You only need to enter enough characters to distinguish between potential matches.

You only need to enter enough characters to distinguish between potential matches.

When I press Tab it adds the rest of the directory name for me.

After entering enough characters to identify the correct directory, pressing the Tab key again completes the directory name on the command line.After entering enough characters to identify the correct directory, pressing the Tab key again completes the directory name on the command line.

After entering enough characters to identify the correct directory, pressing the Tab key again completes the directory name on the command line.

If I wanted to go to a subdirectory, I could start typing its name and press Tab again. You can continue to do this to quickly get to deeply nested subdirectories.

You can use this technique to execute shell commands, program names, and even custom aliases and shell functions. It’s also a quick way to add directory pathnames to commands as parameters.

Some other useful techniques

The last few are pretty well known, but just in case they’re unfamiliar, they’re probably my most used keyboard shortcuts.

  • Ctrl+L clears the terminal window.

  • Ctrl+L closes the terminal window.

  • Super+left arrow Docks the terminal window to the left.

  • Super+right arrow Docks the terminal window to the right.

Faster is better

The command line is an extremely powerful resource, but it can feel limited due to its one-letter-at-a-time interface. Tab terminations and accelerators like cd – can increase speed without losing the accuracy you get from trying to dial too fast.

Faster is better, especially when it’s easier.