Let's say I use CTRL-R and then type tail to find the last time I ran tail.

What comes up is tail -F /path/to/log/file-2011-03-07.log

The command I want to run is the above command, but with 2011-03-08 instead of 2011-03-07. Is there a way to do replace with a regexp via the command line?

r 7=8 tail should do it. Read up on fc and r; they're not very widely known but very useful for this kind of thing.

There isn't regexp editing directly, but if you use fc directly you may be able to play with fc -e a bit. (Indeed, fc -e 'sed -ie s/foo/bar/' command appears to work. You might be able to wrap that in a function.) There's also -m to use a shell glob to select the command from history.

  • Your answer directed me zshexpn(1) where I was able to find out that I could do something like this: !tail:s/6/7 Which kind of does what I want. Will take a look at r, fc and zshexpn(1) more to see what is possible! – staackuser2 Apr 7 '11 at 1:44

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.