DEV Community

Discussion on: 10 simple Linux tips which save 50% of my time in the command line

Collapse
 
irobertson profile image
Ian Robertson • Edited

One key I love in Bash and Zsh is meta-dot (or alt-period or escape-period). It is a bit like up arrow, but rather than replacing the curren line, it inserts the last word of the previous line. Pressing it multiple times cycles through multiple preceding lines.

For example, you just ran

somecommand > longfilename

and want to open the resulting file in vi, you can type

vi meta-dot

and longfilename will be inserted on your command line after vi.

Collapse
 
javinpaul profile image
javinpaul

Wow, nice to know that, how do you type meta-dot? just literal?

Collapse
 
irobertson profile image
Ian Robertson

Depends on your keyboard layout; most likely your meta key is "alt", so typing a period while holding down the alt key would do the trick. You can also type the escape key, followed by a period.

Collapse
 
5422m4n profile image
Sven Kanoldt

Whether you are in bash or zsh, you can use the ! operator quite flexible:

If we take: echo a b c d as an example

!$          # the last argument: d
!:*         # all the arguments: a b c d (can be shorten !*)
!:1         #  the first argument: a (same as !^)
!:1-3       # arguments from first to third: a b c
!:2-$       # arguments from the second to the last one: b c d