Professional Documents
Culture Documents
A cheat sheet for moving around and editing your command line – Bash
Edition.
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 .
Navigating and Editing the Command Line (Bash Edition)
# Using history
CTRL+r Backwards search in previously executed commands (history)
CTRL+p Previous command (same as Up arrow)
CTRL+n Next command (same as Down arrow)
# Swap 'em!
CTRL+t Swap the last two characters before the cursor
ALT+t / ESC+t Swap current word with previous
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:
$ man bash
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!
« Escaping Developer Nightmares Disposable Docker Containers »
Related Posts
Rustam Mehmandarov
Tweet Share
Passionate Computer Scientist