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.

Often I'll execute a command in bash, press the up arrow to retrieve it from history, edit it, and execute the edit. However, sometimes I'll decide to discard the edit and run a different command or something. This poses a problem because the edited command, which I didn't run, gets saved over top of the original history entry so I can no longer run the original with ease.

For example, here's the end of my current history:

2132* svn cleanup && svn up --set-de
2133  history

The first command was originally svn cleanup && svn up --set-depth=infinity folder1 folder2.

Is there a way to disable overwrites or revert them to the original commands?

share|improve this question
    
Zsh behaves the way you want. –  Gilles Jan 28 '13 at 22:35

1 Answer 1

Abort the line editing with ctrl+c instead of deleting the command, that way bash doesn't overwrite the history line.

share|improve this answer
    
This works, thanks for the quick response! I usually press up or down to move to another history entry however, rather than backspacing the line clear -- if I'm more than a couple lines up into the history I'll also be annoyed/slowed by Ctrl+C losing my place and needing to tap up again. –  Matthew Read Jan 28 '13 at 18:59

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.