Using Linux means using the command line sooner or later. But typing commands in a terminal window can be slow and repetitive. These keyboard tips will turbocharge your terminal window experience.
Linux is a command line operating system. You can choose to drop a desktop environment on top of it, such as the GNOME or KDE desktop environments, but still have a text interface underneath that hasn’t really changed since the days of the first Unix implementations in the 1970s.
In a terminal window, Linux uses a shell like Bash to read or act on your commands or pass them to the appropriate command or program.
New shells have been released, old ones have been completely retired, and some of the long-standing ones have had updates. Regardless, what hasn’t changed is the need for users to type commands. The user must type their instructions on the command line, just like half a century ago.
Commands must be spelled correctly, and since they are case sensitive, each letter must be spelled correctly. Commands also contain all kinds of characters, and if they span file system paths, they can be very long. And the longer the command and the more unusual characters it contains, the greater the risk of errors.
Learning the countless Linux commands and harnessing the power of the command line is hard enough without dealing with typos and other keyboard errors.
The hints, tips, and tricks we’ll show you will make using the command line faster and more productive.
RELATED: Command lines: Why do people still bother with them?
Completion of the schedule
If you provide enough letters for the shell to match a command, file name, or folder name, pressing Tab will insert the appropriate command, file name, or folder name for you on the command line.
In our home directory on our test computer, we wrote the following:
Then we press the “Tab” button.
The rest of the “Documents” have been added for us. You can keep doing this to complete an entire path.
We know that we have a directory called “projects” in our “Documents” directory, so typing “pro” and hitting “Tab” completes that for us as well.
If you can’t remember what the name of the next directory starts with, double-click the Tab key and the shell will show you a list of possible directories. It then fills the command line with as much as you type and waits for more input.
Type a few letters of the directory you want – just enough to distinguish it from other entries – and press Tab to have the shell add it to your command line.
If you don’t type enough characters to uniquely identify the directory you want, you’ll see a list of directories that match what you’ve typed so far.
Using Tab to create directory paths is an easy way to increase productivity. Tab completion is also smart, behaving differently for different commands. If you used
ls instead of
cdit knows that it must contain files as well as directories.
Double-clicking the Tab key will include files in possible matches.
You can also use Tab with command names. let’s say you want to use
systemctl command to activate a daemon. Type “sudo sys” and press the “Tab” key twice.
You will see all commands starting with “sys”.
Add “temc” to your command and hit “Tab” again to complete “systemctl”. Now type “en” and press “Tab”.
sudo systemctl en
The rest of the word “enable” is added to your command line.
The best way to avoid typos is to not type at all. Use “Tab” and let the shell do it for you.
Editing Keyboard Shortcuts
As much as it helps to complete the tab, you’ll still find that you need to go through the command you typed and make changes.
There are a number of key shortcuts that will speed up your actions and edit on the command line. Get these into your muscle memory and you’ll never hold down the arrow keys again waiting for the cursor to track back and forth.
- Ctrl+A: Go to the beginning of the line. With the same House.
- Ctrl+E: Go to end of line. With the same End.
- Alt+F: Advance the line a word instantly. With the same Ctrl+Right Arrow.
- Alt+B: Move backwards from the line a word instantly. With the same Ctrl+Left Arrow.
- Ctrl+F: Advance the line one letter instantly. With the same Right Arrow.
- Ctrl+B: Move backwards from the line one letter instantly. With the same Left Arrow.
These shortcuts delete text.
- Ctrl+U: Delete from the cursor position to the beginning of the line.
- Ctrl+K: Delete from the cursor position to the end of the line.
- Ctrl+W: Delete one word to the left. With the same Alt+Backspace.
- Alt+D: Delete the word on the right.
- Ctrl+/: Return it. Yes, there is a undo option on the command line.
A quick “Ctrl+U, Ctrl+K” will delete the entire line.
Why bother rewriting something you’ve already written once? Bash stores your previous commands in the command history and allows you to repeat any command.
RELATED: How to use the date command in Linux
You can use the Up Arrow and Down Arrow keys from the command line to view the list of commands. Pressing Enter will execute the specified command. you can use
history command to see the entire list of commands.
Commands are numbered.
“!” to repeat any of the commands. use an exclamation mark. the number of the command you want to use again immediately after. Do not put a space after the exclamation point.
You can use the beginning of the command instead of the command number. For example, if you use
!geditthe shell will execute the last command you used starting with “gedit”.
You may want to use it to be safe
:p (print) modifier. This prints the command but does not execute it. Again, do not include any spaces in the command.
If the found command is one you want to run, you can run it by pressing the Up Arrow key and then Enter to put it back on the command line. Of course, if you need to press the Up Arrow key and then change the command, you can edit it before pressing Enter.
Two exclamation marks “
!!” represents the last command. If you forget to use it
sudo with command just “sudo !!” write. to re-execute the last command with
Another useful information you can use Alt+. (period) to append the last word of the previous command to the command line.
Interactive History Search
Press Ctrl+R to start the search. Then type a few letters of the command you are looking for and press Ctrl+R.
If a match is displayed but it’s not the command you want, press Ctrl+R again to move to the next match. Keep pressing Ctrl+R until you see the command you want.
Pressing Enter will execute the command, pressing Home, End, Right Arrow, or Left Arrow will allow editing before running the command.
Ctrl+G will exit the search without doing anything.
Other Useful Shortcuts
These shortcuts are also a must.
- cd: Takes you to your home directory. With the same
- cd-: Jumps back and forth between your two most recent directories.
- Ctrl+l”: Clears the terminal window. It’s the same as the clear command, but it doesn’t close your history.
- Ctrl+d: Closes the terminal window. It’s the same as the logout command, but it doesn’t close your history.
- Super Key + Arrow keys: Snaps and resizes your Terminal window to the left and right of your screen, full size and normal size.
How to learn these keys
Make a short list of the most useful sounding commands and write them down on a piece of paper. Keep it close, refer to it and use these buttons.
Once you have these, start a new shortlist.
RELATED: 37 important Linux commands you should know