12

How can I enter some kind of "private" zsh shell session where none of my commands will be recorded in the on-disk history?

I know there is an option for adding a space character before any/each command to avoid it being recorded in the history, however, I'm looking for a solution that is not requiring adding a space in front of each command.

1 Answer 1

24

Launch a new zsh shell and disable history within it.

Option 1

zsh unset HISTFILE ...secret commands... exit 

The secret commands won't be stored in the history file.

Option 2

zsh fc -p ...secret commands... exit 

The fc -p will switch zsh to a in-memory history that will be discarded when you exit.

The downside: the previous history (commands entered before the private session started) will not be available.

2
  • Great answer. One small note. For me running echo $SHELL from zsh returns /bin/bash. I believe it points to login shell rather than current shell Commented Apr 12, 2024 at 18:53
  • @RaZ0rr Good point, I'm removing my command suggesting using $SHELL then, to avoid any confusion. Commented Sep 2 at 14:14

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.