Hacker News new | ask | show | jobs
by Sukotto 4704 days ago
You could also just replace the incorrect part of the previous command with ^old^new. I use that a lot when I want to doublecheck before taking a permanent action.

eg. Check what you're about to delete

  $ ls *.backup
  a.backup    b.backup    c.backup
  
  $ ^ls^rm
  rm *.backup

Something else that saves a lot of time is to incremental-search backwards through your command history using ctrl-r instead of arrow keys. eg. cycle through every "grep". Press ctrl-r, type grep, and it jumps to to most recent command that contains "grep". Each time you press ctrl-r it will jump further back in time. If it's something you expect to search for a lot, you can even tag commands with # comments then search for the comment. (There's a fine line there though... if you reuse a command really often you should probably alias or script it)

Command history uses the 'readline' library so all(?) the other editing-related emacs chords will work on it ctrl-a/ctrl-e to jump to the start/end of the line, ctrl-r/ctrl-s to search, alt-f/alt-b to jump words, etc. Oh, and an emacs kill-ring too, that's pretty useful.

Enjoy.

...

...

But there's one more thing.

This is a feature of GNU Readline, not a feature of bash. Other apps that use readline will also accept these chords.

Things like the ruby and python shells, mysql, etc.

You think you can do a lot in those tools now? Learning to leverage everything that readline gives you will take you to a whole new level.

Have fun exploring :)