DEV Community

Cover image for Leveling Up Your Terminal/Command-Line Navigation
Dylan Paulus
Dylan Paulus

Posted on • Originally published at dylanpaulus.com

Leveling Up Your Terminal/Command-Line Navigation

One motivating factor in using a terminal is the productivity gains... that is, once you can sweep the keyboard like an 80's metal guitarist. Getting a few basic keyboard shortcuts/commands down can drastically improve the usability of the terminal. Let's take a look at a few of my favorites.

(I'll be showing off Git Bash in this article, but these commands work in most terminals)

Movement

Move to the end of the input
ctrl + e

Move to the end of the input

Move to the beginning of the input
ctrl + a

Move to the beginning of the input

Move between each 'word'
ctrl + [arrow left/right]

Move between each 'word'

Deleting

Delete backwards a whole 'word'
ctrl + w

Delete backwards a whole 'word'

Delete everything
ctrl + u

Delete everything

Open File Explorer

Opening the file explorer at the current location can be super useful. The command varies based on operating system.

(Open file explorer at the current directory. Change '.' to be any location!)

Windows: explorer .
Unix/MacOS: open .

Open File Explorer

History

Rerun the last command
!!

Rerun the last command

Get the full history of commands
history

Rerun command from the History
![#number]

history

End

These are shortcuts/commands I find myself going to daily that make the terminal a pleasure to deal with. Are there any I missed that you love? Let us know in the comments!

Photo by Josiah Weiss on Unsplash

Top comments (7)

Collapse
 
anduser96 profile image
Andrei Gatej • Edited

Thanks for sharing!

I would also add:

  • CTRL + SHIFT + T: create a new terminal tab

  • CTRL + SHIFT + W: close the current terminal tab

  • mkdir path/to/dir && cd $_: create a directory and cd into it as soon as it is created; the same concept can be applied to files

Collapse
 
mitjmcc profile image
Mitch McClellan

It would be useful to set an alias for that last one.

Collapse
 
thomasjunkos profile image
Thomas Junkツ • Edited

Little aside:

  • These are the default emacs-style commands.
    If you are more into vi there is the possibility to use that: set -o vi.

  • The use of a other shell than bash (e.g. zshell) will improve your experience further (TAB-completion is meh! under bash)

  • In case you intend to use fish, you have to unlearn too many things. Use at your own risk.

Collapse
 
nghuuphuoc profile image
Phuoc Nguyen

Thank you for the great post. I didn’t know about ![#number].

Collapse
 
thomasjunkos profile image
Thomas Junkツ

Wait until you see !-2 ;)

Collapse
 
ganderzz profile image
Dylan Paulus

woah

Collapse
 
nikhilmadhamshettiwar profile image
Nikhil Madhamshettiwar

Thanks a lot for this.. you saved lot of my time :)