Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Imagine you've just run a dozen commands. Say...

$ cd foo/    # history cmd #10000 (my history is very long)
$ ... more commands ...
$ cd ../     # history cmd #10012 

I know I can re-run them concatenated with !-12 && !-11 && !-10 && (and so on) && !! if they happen to have just been run (unlikely) or !10000 && !10001 && !10002 && (and so on), but is there a simpler way than hand-typing each history number with a bang and ampersands?

Is there perhaps some kind of range thing I'm unaware of in bash?

e.g. !{10000-10012} # something like this, only working.

share|improve this question
add comment

1 Answer

up vote 7 down vote accepted

This is what the fc command is for.

fc -12 -1

or

fc 10000 10012

This is not quite what you want as it will launch an editor first, but that is probably a good thing since it gives you a chance to double check that you have the correct commands and even edit them using all the capabilities of your favorite editor. Once you save you changes and exit the editor, the commands will be run.

share|improve this answer
    
Ah hah! Brilliant! fc. Fix Commands. Makes sense! –  Gabriel Oct 9 '12 at 16:42
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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