sophie: A cartoon-like representation of a girl standing on a hill, with brown hair, blue eyes, a flowery top, and blue skirt. ☀ (Default)
[personal profile] sophie posting in [community profile] command_liners
A quick tip for bash users that I use all the time:

If you have a command in your history that you want to re-execute or edit, but don't want to keep tapping the up key, hit Ctrl-R and then start typing part of the line. bash will find the last line matching your input on the fly. If it's not the one you want, either keep typing until it is, or hit Ctrl-R and bash will show you the next match.

Once you've got it, you have two options: to execute, you can then just press RETURN; to edit, use a movement key (left/right arrows, Home/End, etc) and bash will drop you back to a standard command line with the line you just found.

This trick also works if you know the middle of the line but not the beginning, since bash searches the entire line.

[edited to add: BTW, Fey, do you realise that nobody can add new tags to posts in this community? The only tags in here are ones first used by you. :)]

Date: 2010-08-03 09:47 pm (UTC)
foxfirefey: Fox stealing an egg. (mischief)
From: [personal profile] foxfirefey
FIXED! Thanks for the reminder!

Date: 2010-08-04 02:14 am (UTC)
afuna: Cat under a blanket. Text: "Cats are just little people with Fur and Fangs" (Default)
From: [personal profile] afuna
Oh nice; I use Ctrl-R, enter a lot, but I wasn't aware that you could just edit. Nifty!

Date: 2010-08-04 02:29 am (UTC)
vass: Small turtle with green leaf in its mouth (Default)
From: [personal profile] vass
That's so cool!

Date: 2010-08-04 05:35 am (UTC)
jld: “0wned!!!” (0wned)
From: [personal profile] jld
The other fun thing with C-r is that it works within a line. So if you want to do the last command but change the part after the last /, then it's up C-r / C-k and then type… oh, huh. That also works without the up-arrow, I guess. I'll have to remember that.

Because for history search I've become a big fan of using zsh's tab-completion, which does everything, to expand csh-style history references. And then C-_ to undo and fix it if it gets the wrong thing. So it's gotten to the point that I only rarely use C-r for that. (And I got started with emacs and bash, so I used to use it a lot, too.)

Date: 2010-08-04 12:16 pm (UTC)
pne: A picture of a plush toy, halfway between a duck and a platypus, with a green body and a yellow bill and feet. (Default)
From: [personal profile] pne
And in ksh with vi bindings, ESC /.

Though I imagine not many people who read this use that, but it was what I had at work for many years on a HP-UX machine.

Profile

command_liners: A command line prompt with a blinking cursor after it, green against black. (Default)
Command Liners

January 2022

S M T W T F S
      1
2 345678
9101112131415
16171819202122
23242526272829
3031     

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Aug. 15th, 2025 03:24 am
Powered by Dreamwidth Studios