1

I'm working on a project that requires compilation for each test run. Every time I want to test it out again I press Up to get the last command and Enter to run it. The issue is that it fills my History up, so if I want to use a command from before I started a coding session, it's completely buryed in hundreds of the same exact command.

How can I run a command without it filling up my History?

And if there isn't a way to do that, is there some way to skip over repeats when going back in History?

I am not totally certain what shell I am using. I am running Terminal, on OSX. But I would like the answer for as many different shells as is known, because that would make this question more valuable for others later.

$ echo $0
-bash

EDIT: After a short discussion in comments and some additions to the original text of the question, better search results have appeared in the sidebar, showing this is a duplicate of How to stop Bash appending history. I'll be marking it as so and closing it.

Seph Reed
  • 203
  • Which shell are you using? Bash? – muru Nov 14 '17 at 07:32
  • Or do you want all of the different answers for the various different shells? – JdeBP Nov 14 '17 at 07:32
  • Not totally certain. Terminal in OSX, but as many as you know off the top of your head would make this question more valuable for others later. – Seph Reed Nov 14 '17 at 07:32
  • I think OSX defaults to bash – EightBitTony Nov 14 '17 at 07:34
  • Terminal is a terminal emulator program. It is not the shell that you are using. You are probably using the Z Shell, possibly a heavily customized one. But you might not be. Start with echo $0 and do not put this stuff in comments. [edit] your question to improve it. – JdeBP Nov 14 '17 at 07:35
  • Something I don't see mentioned in this or the linked answer is simply adding a space as the first character of your command, which will prevent it from being inserted in .bash_history. So, you can just type a space followed by !! to rerun the previous command without an additional entry in the history. – m0dular Nov 15 '17 at 00:04
  • I know you're an op but I don't think it's a duplicate. Your question has a very direct answer: !! (that is "space bang bang") - space prevents adding to history and double bang repeats last command. – cprn Nov 06 '20 at 13:40

0 Answers0