How To Clear Shell History In Ubuntu Linux

How do I clear the shell history in Ubuntu Linux? How can I clear terminal command history in Ubuntu Linux? How do I clear bash history completely on Ubuntu Linux?

Command history allows you to find and reissue previously typed commands. History expansions introduce words from the history list into the input stream, making it easy to repeat commands, insert the arguments to a previous command into the currentinput line, or fix errors in previous commands quickly. You may pass sensitive information such as passwords and it is stored in shell history file. Use the following tips to either delete your history or disable it.
Tutorial details
Difficulty Easy (rss)
Root privileges No
Requirements None
Time 1m

How to clear bash shell history command

The procedure to delete terminal command history are as follows on Ubuntu:

  1. Open the terminal application
  2. Type the following command to to clear bash history completely:
    history -c
  3. Another option to remove terminal history in Ubuntu:
    unset HISTFILE
  4. Log out and login again to test changes

Let us see all examples and usage in details to remove shell history in Ubuntu when using bash.

Finding info about your history

To get name of the history file, type:
echo "$HISTFILE"

So my history is stored in /home/vivek/.bash_history file. It can store up to 1000 commands by default. To see your current settings run the following echo command echo "$HISTSIZE"

To see current history, run:
history | grep 'du'

The grep command used in last to filter out history.

Command to clear Ubuntu bash history

To clear the history, type the following command:
history -c
rm ~/.bash_history
You can add the command to your ~/.bash_logout so that history will get cleared when you logout:
echo 'history -c' >> ~/.bash_logout

Prevent a bash history file from ever being saved

Add the following commands to ~/.bashrc file:
echo 'unset HISTFILE' >> ~/.bashrc
echo 'export LESSHISTFILE="-"' >> ~/.bashrc

A list of history shell variables

Bash shell variable Description/Usage
export HISTFILE=~/.my_shell_history
The name of the file in which command history is saved. The default is $HOME/.bash_history.
export HISTFILESIZE=50000
The maximum number of lines contained in the history file.
export HISTSIZE=50000
The number of commands to remember in the command history. The default is 500. If the value is 0, commands are not saved in the history list.
export HISTTIMEFORMAT="%d/%m/%y %T "
If this variable is set and not null, its value is used as a format string for strftime(3) to print the time stamp associated with each history entry displayed by the history builtin. If this variable is set, time stamps are written to the history file so they may be preserved across shell sessions. This uses the history comment character to distinguish timestamps from other history lines.
# Ignore these commands
A colon-separated list of patterns used to decide which command lines should be saved on the history list.
#Dont put duplicate lines in the history
export HISTCONTROL=ignoreboth
A colon-separated list of values controlling how commands are saved on the history list. If the list of values includes ignorespace, lines which begin with a space character are not saved in the history list. A value of ignoredups causes lines matching the previous history entry to not be saved. A value of ignoreboth is shorthand for ignorespace and ignoredups. A value of erasedups causes all previous lines matching the current line to be removed from the history list before that line is saved. Any value not in the above list is ignored.

For more info read bash command man page online or offline by typing the following command:
man bash
help history

See “A Shell Primer: Master Your Linux, OS X, Unix Shell Environment” for more info.

🐧 Please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on Linux, Open Source & DevOps via:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
11 comments… add one
  • Jonas Sep 7, 2011 @ 14:27

    guess you mean
    echo ‘history -c’ >> ~/.bash_logout
    …to clear history on logout?


  • Brett Alton Jul 31, 2013 @ 16:24

    Jonas is correct, FYI, in case you want to update this post…

    • 🐧 nixCraft Aug 1, 2013 @ 6:03

      @Jonas/ Brett:

      Thanks for the heads up!

      • Brett Alton Aug 1, 2013 @ 17:13

        Np, thanks for the wonderful website!

  • shan Aug 8, 2013 @ 6:55

    any of you guys know how to make sure your history is NEVER wiped out?

    i use the amazing
    incremental history searching from here

    and would like to always have my history
    whereas on Ubuntu it gets wiped out every so often

    i guess it will be something like echo ‘whateveristhecommandhere’ >> ~/.bashrc

  • manzoor Mar 11, 2014 @ 12:00

    I personally like to use this basic command to clear the history

    # history -c

    history [option] – c means clear the history

  • Programster May 3, 2014 @ 8:34

    I just tried this on ubuntu 14 and found that history -c did NOT remove the contents of my .bash_history file, so I have to run both commands:

    “`history -c
    rm ~/.bash_history“`

  • Rohit Mane Jun 3, 2014 @ 15:24

    i know but how to delete history perminentely ????

  • javier Jan 24, 2015 @ 17:45

    That was useful. Is there any chance to recover deleted history?

    • me@Javier Oct 4, 2015 @ 12:48

      File recovery programs on the ~/.bash_history which is obvious. Learn about file recovery on Linux (e.g. versus Windows or Mac), for an overview of basic computer forensics.

  • Aiko Dec 21, 2020 @ 13:43

    I wanted ubuntu how to delete history and this page helps tons of me. thanks. sorry english not 1st lang

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Problem posting comment? Email me @