0

This question already has an answer here:

When I use a browser, I can "browse in private" if I don't want my browser history recorded on the local machine. But what if I'm typing commands in the bash shell and maybe passwords, and I don't want that stored in my command history, but at the same time I don't want to wipe out my command history? Is there a way to do that?

marked as duplicate by don_crissti, user4556274, GAD3R, DopeGhoti, Community Jan 25 '18 at 22:38

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • No matter your settings, don't type passwords that matter as arguments on the command line! – Wildcard Jan 25 '18 at 22:44
3

UPDATE: My answer was marked ACCEPTED before the question was marked as duplicate. The reference points out a solution possibly superior to the three I list below, depending on your use-case, so I'll repeat it here: Temporarily turn off history logging by typing set +o history, and restore history logging by typing set -o history.

ORIGINAL ANSWER(S): In bash, there are a few ways to manually create the environment you seem to want, all involving some combination of the internal bashvariables, HISTCONTROL, HISTFILE and HISTIGNORE.

In the paragraphs below, quotations are verbatim from man bash.

1] You could start a shell with HISTFILE unset, in which case "the command history is not saved when a shell exits".

2] You could manually set HISTCONTROL to include the string ignorespace, in which case "lines which begin with a space character are not saved in the history list.

3] You could manually set HISTIGNORE to *, or to something more specific, in which case lines matching your glob pattern(s) will not be saved. For this option, do read the man page carefully, because there are several caveats and gotchas. That section of the man page is short and clear, and its good practice to read it anyway, so I'm not cutting and pasting it here.

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