> ## Content Index
> Fetch the complete content index at: https://snubmonkey.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# How to Remove/ Disable Zsh History' Commands on Linux.
- URL: https://snubmonkey.com/how-to-remove-disable-z-shell-command-history-on-linux/
- Published: 2022-09-21T15:23:00.000Z
- Updated: 2025-04-16T22:32:50.000Z
- Description: This is the ninth in a series of posts featuring Protips, tips, tricks, hacks, and secrets provided by Our Team 🙊 — We want to share our top tips for the growing and thriving Linux community out there. Because sometimes you need a little help...
- Author: yannick Coffi
- Tags: tips, how to 🪄, linux 🐧

Linux's shell history is a fantastic feature letting you recall the list of previously typed commands. But there are instances, though, when you want to disable it. You might want to disable your Z shell commands history on a production server —accessible from outside, where a potential attacker could gain access and re-read your history file to look for potential commands, services in use, or accidentally inserted passwords.   
  
Below are a number of instructions on how to disable your history storage or remove all currently saved commands. This feature was not available in the Bourne shell.

## Find out the number of commands saved in `history`

In the **Z shell**, your command history is stored in a file `.zsh_history` in your home directory. By default, `history` displays a numbered list of the 500 t0 1000 most recent commands, from oldest to newest. The **HISTSIZE** variable specifies the number of instructions to preserve in a history list.

```bash
$ echo "$HISTSIZE"

Output

1000
```

The Linux shell allows you to adjust the number of commands stored in history. It provides two distinct options: the `HISTFILESIZE` parameter determines how many commands are kept in the history file, while `HISTSIZE` controls the number stored in memory for the current session.

Search for both the `HISTSIZE` and `HISTFILESIZE` parameters if not present add them and feel free to modify its values. For the purposes of this tutorial, saving 10000 lines to disk and loading the last 5000 lines into memory will work just fine.

```bash
$ nano ~/.zhrc

...
..
.
# history length HISTSIZE and HISTFILESIZE setting
HISTSIZE=5000
HISTFILESIZE=10000

```

## Where are my `history` commands stored?

  
The history is created from the file specified by the variable **HISTFILE**.  
`/.zsh_history` is the default file.

```bash
$ echo "$HISTFILE"

Output

/home/linux/.zsh_history

```

## Avoid duplicate entries in `history`

To avoid duplicate entries in your history, edit your **`~/.zshrc`** file:

```bash
$ nano ~/.zshrc

Add the following at the end

export HISTCONTROL=ignoredups
```

  
Alternatively, use the following one-liner:

```bash
$ echo "export HISTCONTROL=ignoredups" >> ~/.zshrc

```

  
To apply these settings immediately for the current shell session execute the `.zshrc` file:

```bash
$ . ~/.zshrc

or

$ source .zshrc

```

We can control these duplicates using the **HISTCONTROL** variable. **HISTCONTROL** can have the following values:

- **ignorespace** \- lines beginning with a space will not be saved in history.
- **ignoredups** \- lines matching the previous history entry will not be saved. In other words, duplicates are ignored.
- **ignoreboth** \- is shorthand for "ignorespace" and "ignoredups" values. If you set these two values to HISTCONTROL variable, the lines beginning with a space and the duplicates will not be saved.
- **erasedups** \- eliminate duplicates across the whole history.

You can also set multiple values to the **HISTCONTROL** variable with colon-separated as such:

```bash
$ export HISTCONTROL=ignoredups:erasedups

```

## Clear `history`

To clear both the history file and any presently unsaved commands in the history file, use the following Linux command. 

**ps**: You will no longer be able to view history for both saved and unsaved history commands after running the aforementioned command.  

```bash
$ history -c

```

## Disable `history` on Linux

You may delete the **HISTFILE** shell variable by using the `unset HISTFILE` command by adding the above line to the end of the `~/.zshrc`:

```bash
$ echo 'unset HISTFILE' >> ~/.zshrc
```

## Permanently disable `history` using `set` command

Another method is to use the set builtin command with the `+o history` option and add it to the end of the `~/.zshrc`:

```bash
$ echo 'set +o history' >> ~/.zshrc

```

  
Next time a user login to the shell it will not store any commands to the history file **.zsh\_history**.

To apply these settings immediately for the current shell session execute the `.zshrc` file:

```bash
$ . ~/.zshrc

or

$ source .zshrc

```

## Disable the `history` system-wide  

  
It will disable the command history system-wide and will be effective for the newly created users.  

```bash
$ echo 'set +o history' >> /etc/profile

```

##   
Delete a single command in `history`

This will delete a single command number 66 from `history` :  

```bash
$ history -d 66

```

## Bonus: Clear `history` on a remote host

  
The following command will blank the history file.  

```bash
$ ssh user@linuxserver "> ~/.zsh_history"

```
  
  
We hope you have found this post as useful and informative as we do.