banner
Previous Page
PCLinuxOS Magazine
PCLinuxOS
Article List
Disclaimer
Next Page

BASH Command Line Shortcuts


by Paul Arnote (parnote)

Many users of today's Linux are happy using Linux via the various graphical user interfaces that are available, such as KDE, Mate, Xfce, LXDE/LXQt, Trinity, Openbox, Enlightenment, Gnome, Fluxbox, etc. Yet, there are many who go on to learn to use the Linux command line. Those users usually discover that the command line is not as hard as they feared, can wield a lot of power, and can often accomplish tasks a lot faster than can be done via a graphical program.

Eventually, even the most ardent GUI user will find himself or herself needing to use the command line. Knowing a bit about the command line will help in those situations. Knowing some shortcuts will make that command line excursion a bit faster.

So, let's take a look at some common command line shortcuts. We'll put them into sections, both to keep similarly functioning commands grouped together, and to help you find them later, should you ever need to reference them.



Screen Control

Crtl + L will clear the screen. You can also clear a terminal screen by simply typing clear and pressing the Enter key.

Ctrl + S will pause command output to the screen. This is especially useful when you have a command that produces verbose output, but you don't necessarily want to read all of that output.

Ctrl + Q will resume command output to the screen that was previously paused by the Ctrl + S shortcut.


Command Line Navigation & Editing

Learning the shortcuts for navigating and editing the command line are a huge time saver. There are quite a few, but it is worth learning at least the ones you use a lot. Instead of trying to learn them all at once, you might want to start with learning the navigation shortcuts, and then add in learning the editing shortcuts after you gain proficiency with the navigation shortcuts.

Ctrl + a or Home will move the cursor to the start of the line.

Ctrl + e or End will move the cursor to the end of the line.

Ctrl + b or Left Arrow will move the cursor back one character at a time.

Ctrl + f or Right Arrow will move the cursor forward one character at a time.

Ctrl + Left Arrow or Alt + b or Esc then b will move cursor back one word at a time.

Ctrl + Right Arrow or Alt + c or Esc then f will move cursor forward one word at a time.

Ctrl + k will delete from the current cursor position to the end of the command line.

Ctrl + u will delete from the current cursor position to the start of the command line.

Ctrl + w will delete from the current cursor position to the start of the next word (i.e. delete backwards one word).

Ctrl + y will paste word or text that was cut using one of the deletion shortcuts (such as the one above) after the current cursor position.

Ctrl + x then Backspace will remove all of the text from the current cursor position to the start of the line.

Ctrl + xx will move between the start of the command line and the current cursor position (and back again).

Alt + d will delete to the end of the word, starting at the current cursor position (or the whole word if the cursor is at the beginning of word).

Alt + c will capitalize to the end of the word, starting at the current cursor position (or the whole word if the cursor is at the beginning of word).

Alt + u will make all letters uppercase from the current cursor position to the end of the word.

Alt + l will make all letters lowercase from the current cursor position to the end of the word.

Alt + t will swap the current word with the previous word.

Ctrl + d or Delete will delete the character under the current cursor position.

Ctrl + h will delete the character before the current cursor position.

Ctrl + t will swap the character under the current cursor position with the previous character (useful if you made a spelling/transposition error while typing a command).

Esc, then T, will transpose the two words immediately before (or under) the cursor.

Esc, then U, will transform the text from the cursor to the end of the word to uppercase.

Esc, then L, will transform the text from the cursor to the end of the word to lowercase.

Esc, then C, will change the letter under the cursor (or the first letter of the next word) to uppercase, leaving the rest of the word unchanged.


Controlling Processes

You can also use some bash command line shortcuts to help control the various processes running on your computer.

Ctrl + z will suspend the current foreground process. To bring the process back to the foreground, enter the fg [process_name] command. This will allow you to temporarily pause a process, use the terminal for other tasks, and then resume it later.

Ctrl + c will stop the running program in its tracks.

Ctrl + d is the same as executing the exit command, causing the bash shell to exit.

Ctrl + r will help you find the last matching command to your "search" criteria. Type Ctrl + r, followed by words used in your last command, and Linux will find that command for you. Then, just press the Enter key.

history | grep [keyword] will search the bash history and bring up the matching command. This is especially helpful if you forget the proper formatting for a command.

Typing --help after most commands will display the options for that command. In many instances, it's enough to jog your memory to get you through using a seldom used command.


Bash Bang(!) Commands

!! will execute the last command.

![command] will execute the last command specified by the [command] parameter.

![command]:p will display the command that ![command] would run, and moves it to the latest command in the command history.

!$ will execute the last "word" of the previous command. So, if you typed cat myfile.txt as your last command, it would try to run myfile.txt as the command.

!$:p will display the last "word" of the previous command that !$ would execute. This can also be achieved with Alt + . .

!* displays the last word of the previous command.

!*:p displays the last word that !* would execute.


Summary

So there you have it. There are a lot of ways to help make your interaction with the bash command line easier and faster. Even if you're not a "command line commando," you owe it to yourself to learn some of these time saving shortcuts. Eventually, you WILL find yourself facing the command line. It's not a matter of IF, but WHEN. Minimally, you might want to print out this article for that inevitable eventuality, just to provide a quick reference.



Previous Page              Top              Next Page