Transform Your Terminal Experience: Time-Saving Bash Shortcuts That Cut Hours from My Monthly Routine

If you frequently enter commands in Bash, it can take a lot of time to navigate and adjust your inputs for the desired outcome. I’ve encountered plenty of typing mistakes and complex command chains. Fortunately, there are several ways to make typing more efficient, from using shortcuts and hotkeys to discovering hidden features that can ease the process.
Quick Navigation of Bash Commands Without the Mouse
Efficient Cursor Movement Using Just Your Keyboard
Credit: Steve Larner/How-To Geek
When you are using the terminal, there are certain Linux commands that are best avoided. If you understand your commands but make a small error, using navigation hotkeys can save precious time. For instance, pressing Alt + B lets you move one word back, while Alt + F moves one word forward. This is significantly quicker than repeatedly using the arrow keys. For an even faster option, use Ctrl + A to jump to the start of the line or Ctrl + E to go to the end.
I commonly use Ctrl + XX to move to the beginning of a command line and back to my previous position with another press. For example, if you realize that you need to prefix a command with “sudo,” this shortcut lets you quickly navigate back, make the necessary addition, and return to where you were to finalize your command.
Speed Typing Techniques for Bash
Quick Auto-Finish, Repeat, and Append Commands
Credit: Steve Larner/How-To Geek
To reuse the last typed word, particularly filenames or paths, you can use !$ in the Bash prompt before hitting Enter. While it won’t be visible until executed, it’s an efficient method. If you prefer a visual approach, pressing Alt + . lets you paste it into your command line. If encapsulated in quotes, this method also accommodates phrases. This is particularly useful for executing different commands that involve specific paths or filenames.
There are also several useful shortcuts you might not know about, including an undo function using Ctrl + _, the ability to paste back with Ctrl + Y, and using Ctrl + R to auto-complete from your command history, which can be cycled for multiple matches. Additionally, brace expansion can execute commands on multiple items: for example, sudo apt upgrade {App1,App2} or mkdir ~/NewFolder{1..3}, which creates three folders in succession.
Credit: Steve Larner/How-To Geek
When you encounter a command that fails due to missing admin privileges, you can simply type sudo !! to run the previous command with “sudo.” This not only saves time but also reduces errors by eliminating the need to retype the previous command. Autocomplete is another handy tool—by pressing the Tab key during input, Bash attempts to guess commands or filenames based on your history. If there are multiple possibilities, pressing Tab again allows you to scroll through the options, making the command entry much faster and less error-prone.
Using Nano for Efficient Command Editing
Avoid Errors in Long Commands and Prevent Auto-Execution
Credit: Steve Larner/How-To Geek
For lengthy commands that need careful attention, a full text editor like Nano can help. Pressing Ctrl + X followed by Ctrl + E opens the current command in Nano for edits. After making changes, Ctrl + O saves and Ctrl + X exits, executing the command seamlessly in the terminal. This method eliminates the risk of accidental executions from copied code and allows for careful modification of complex commands involving various components.
Editing in Nano not only prevents the risk of executing incorrect commands, but it can also help you create new scripts by loading a filename like nano myscriptname.sh. This way, you can write your code safely and systematically within the terminal environment.
Launching Nano via terminal stores existing command in the “/temp/” folder, permitting temporary edits that clear upon reboot or manual deletion. For permanent files, type nano [yourfilename].sh for saving.
Efficiently Correcting Typos and Modifying Inputs
Quick Editing in the Linux Terminal
Credit: Steve Larner/How-To Geek
Errors can stack up while typing in the terminal, from incorrect spellings to misplaced commands. Utilizing hotkeys can simplify corrections significantly. For example, pressing Ctrl + U deletes everything to the left of the cursor while Ctrl + K removes all data to the right. These shortcuts are also effective when using !! to copy commands; one can erase the right segment and add new elements efficiently.
You can even replace specific words by pressing Ctrl + W to delete the last word, or Alt + D for the next word. Additionally, remember to use Ctrl + Y to paste anything you’ve removed.
Mastering Multitasking in Bash
Switching Directories and Managing Background Processes
Credit: Steve Larner/How-To Geek
The operations in Bash can become quite intricate, leading to multiple running processes. To navigate effectively, I employ the commands pushd and popd for directory management. pushd saves your current directory to a stack allowing you to easily return with popd, making it simpler than the traditional cd command. If you use pushd followed by a directory, it will both change and add that directory to the stack.
To manage multiple directories, you can specify which one to access by adding “+0” or “-0” relative to your stack position. For example, pushd +1 accesses the next directory in the stack, while popd +1 removes it. The commands can effectively streamline navigation and reduce manual backtracking between directories.
Another efficient multitasking feature is suspending jobs with Ctrl + Z and using bg to run them in the background, allowing for focused work on another task. If you need to bring a task back, fg does that. For even smoother operations, you can use the “&” operator to run commands in the background, keeping your terminal usable rather than freezing it.
Creating Aliases for Frequent Commands
Simplifying Commands with Shortcuts
Aliases provide quick access to your commonly used commands, reducing the amount of typing required. I prefer to edit my “.bashrc” file using Nano to set these aliases permanently, but you can also set temporary ones directly in your terminal session. To do this, type sudo nano ~/.bashrc, add your shortcuts, then save and exit with Ctrl + O and Ctrl + X.
Streamlining Bash Usage
While Linux offers superior scripting capabilities compared to Windows, it can also present its own challenges. Mastering shortcuts and efficient typing techniques can dramatically reduce the time spent on commands. I recommend practicing a few essential shortcuts at first, gradually expanding your skills as you become comfortable. This will enhance your overall productivity and allow you to allocate your time to other endeavors.



