Is There a Faster Way to Manually Edit a Bash
Navigating and Editing the Command Line – Bash Edition
- 4 mins
A cheat sheet for moving around and editing your command line – Bash Edition.
- Moving Around the Command Line
- Editing Commands in the Command Line
- Bonus
Using the command line can simplify and even automate many of the operations we do on a computer. However, using the command line can mean quite a bit of typing and a possibly large number of parameters. In this post, I would like to focus on how to navigate the cursor and edit the command line, while leaving all the other Bash tricks for the future posts.
I also have created simple graphics to illustrate some of the main shortcuts listed below. This (hi-res) image can be printed for future reference.
Note: Please note that all commands containing ALT
combinations might not work depending on your system configuration, and most definitely not work on MacOS. Normally, it is because these combinations are mapped to something else. However, you can still use the same shortcuts simply by replacing ALT
with ESC
.
Moving Around the Command Line
So, let's first speak about how to move the cursor around – because using just arrow keys is often not the most optimal way of navigating. Sometimes you might want to go to the beginning of the line, to the end of the line, or simply jump from one word to another, where word – in this context – is set of characters separated by spaces (or sometimes other special characters), or as documentation states it:
A sequence of characters considered as a single unit by the shell. Also known as a token.
Editing Commands in the Command Line
Now that we are able to navigate freely along the command line, it is time to do some modifications. Here, we will see how to delete, cut, paste, and swap words and characters.
Bonus
First, the most obvious – you can always find more gems in the man
pages for Bash both in your terminal and online (for instance on this mirror). To view it in your terminal, type:
Now, over to something different. Since we have been talking about the command line and shells it is worth mentioning some less-known (and sometimes "as a curiosity") shortcuts in another terminal – Command Prompt, cmd.exe
:
Good luck! Try them out and let me know how that goes!
Is There a Faster Way to Manually Edit a Bash
Source: https://mehmandarov.com/navigating-and-editing-the-command-line/