One of the advantages of working in a terminal is that it's faster than most other interfaces. Thanks to the GNU Readline library and the built-in syntax of shells like Bash and Zsh, there are several ways to make your interactions with the command line even faster. Here are five ways to make the most of your time in the terminal.
1. Navigate without the arrow keys
While executing commands on the command line, sometimes you miss a part at the beginning or forget to add certain tags or arguments toward the end. It's common for users to use the Left and Right arrow keys on the keyboard to move through a command to make edits.
There's a better way to get around the command line. You can move the cursor to the beginning of the line with CTRL+A. Similarly, use CTRL+E to move the cursor to the end of the line. Alt+F moves one word forward, and Alt+B moves one word back.
Shortcuts:
- Instead of Left arrow, left, left, left, use CTRL+A to go to the start of the line or Alt+B to move back one word.
- Instead of Right arrow, right, right, right, use CTRL+E to move to the end of the line, or Alt+F to move forward a word.
[ Download a sysadmin's guide to Bash scripting. ]
2. Don't use the backspace or delete keys
It's not uncommon to misspell commands. You might be used to using the Backspace key on the keyboard to delete characters in the backward direction and the Delete button to delete them in the forward direction. You can also do this task more efficiently and easily with some helpful keyboard shortcuts.
[ Want to test your sysadmin skills? Take a skills assessment today. ]
Instead of deleting commands character by character, you can delete everything from the current cursor position to the beginning of the line or the end.
Use CTRL+U to erase everything from the current cursor position to the beginning of the line. Similarly, CTRL+K erases everything from the current cursor position to the end of the line.
Shortcuts:
- Instead of Backspace, use CTRL+U.
- Instead of Delete, use CTRL+K.
3. Execute multiple commands in a single line
Sometimes it's convenient to execute multiple commands in one go, letting a series of commands run while you step away from your computer or turn your attention to something else.
For example, I love contributing to open source, which means working with Git repositories. I find myself running these three commands frequently:
$ git add
$ git commit -m "message"
$ git push origin main
Instead of running these commands in three different lines, I use a semi-colon (;
) to concatenate them onto a single line and then execute them in sequence.
Shortcuts:
- Instead of:
$ git add . $ git commit -m "message" $ git push origin main
$ git add .;git commit -m "message";git push origin main
- Use the
;
symbol to concatenate and execute any number of commands in a single line. To stop the sequence of commands when one fails, use&&
instead:$ git add . && git commit -m "message" && git push origin main
4. Alias frequently used commands
You probably run some commands often. Sometimes, these may be lengthy commands or a combination of different commands with the same arguments.
[ Learn how to install applications on Linux. ]
To save myself from retyping these types of commands, I create an alias for the commands I use most frequently. For example, I often contribute to projects stored in a Git repository. Since I use the git push origin main
command numerous times daily, I created an alias for it.
To create an alias, open your .bashrc
file in your favorite editor and add an alias:
alias gpom= "git push origin main"
Try creating an alias for anything you run regularly.
Note: The .bashrc
file is for users using the Bash shell. If your system runs a different shell, you probably need to adjust the configuration file you use and possibly the syntax of the alias command. You can check the name of the default shell in your system with the echo $SHELL
command.
[ Keep your favorite Git commands, aliases, and tips close at hand. Download the Git cheat sheet. ]
After creating the alias, reload your configuration:
$ . ~/.bashrc
And then try your new command:
$ gpom
Shortcut:
Instead of typing the original command, such as:
$ git push origin main
Create an alias with the alias
declaration in .bashrc
or your shell's configuration file.
5. Search and run a previous command without using the arrow keys
Most terminal users tend to reuse previously executed commands. You might have learned to use the Up arrow button on your keyboard to navigate your shell's history. But when the command you want to reuse is several lines in the past, you must press the Up arrow repeatedly until you find the command you are looking for.
Typically the situation goes like this: Up arrow, up, up, up. Oh, I found it! Enter.
There is an easier way: You can search your history one step at a time using the history
command.
When you use the history
command, the list of commands appears with a number beside each. These numbers are known as the history-number
of the command. You can type !{history-number}
on your terminal to run the command of the corresponding number.
Shortcuts:
- Instead of Up arrow, up, up, up, Enter, type
history
, and then look for thehistory-number
of the command you want to run:$ !{history-number}
- You can also perform this task a different way: Instead of: Up arrow, up, up, up, Enter, use CTRL+R and type the first few letters of the command you want to repeat.
Command-line shortcuts
Shortcut keys provide an easier and quicker method of navigating and executing commands in the shell. Knowing the little tips and tricks can make your day less hectic and speed up your work on the command line.
[ Keep your most commonly used commands handy with the Linux commands cheat sheet. ]
About the author
Anamika is a budding developer from India. She is an open source enthusiast and a computer science undergrad who enjoys learning about new technological innovations. Anamika has been a part of various open source and cloud-native programs as a scholar, volunteer, mentor, and educator. She enjoys talking about her favorite programming language, Python, Linux (without a doubt), and of course, open source. She is interested in collaborating to build and contribute! Her hobbies include writing, listening to music, and traveling.
Browse by channel
Automation
The latest on IT automation for tech, teams, and environments
Artificial intelligence
Updates on the platforms that free customers to run AI workloads anywhere
Open hybrid cloud
Explore how we build a more flexible future with hybrid cloud
Security
The latest on how we reduce risks across environments and technologies
Edge computing
Updates on the platforms that simplify operations at the edge
Infrastructure
The latest on the world’s leading enterprise Linux platform
Applications
Inside our solutions to the toughest application challenges
Original shows
Entertaining stories from the makers and leaders in enterprise tech
Products
- Red Hat Enterprise Linux
- Red Hat OpenShift
- Red Hat Ansible Automation Platform
- Cloud services
- See all products
Tools
- Training and certification
- My account
- Customer support
- Developer resources
- Find a partner
- Red Hat Ecosystem Catalog
- Red Hat value calculator
- Documentation
Try, buy, & sell
Communicate
About Red Hat
We’re the world’s leading provider of enterprise open source solutions—including Linux, cloud, container, and Kubernetes. We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.
Select a language
Red Hat legal and privacy links
- About Red Hat
- Jobs
- Events
- Locations
- Contact Red Hat
- Red Hat Blog
- Diversity, equity, and inclusion
- Cool Stuff Store
- Red Hat Summit