How to clear history in Ubuntu
Today's article will show you how to delete historical data on the Bash shell, file manager and text editor on Ubuntu Linux.
Delete command history in Bash
Linux is a command-line based operating system. From file management to program configuration, almost every action in Linux is performed as a terminal command. Over time, these commands will pile up on the Bash system shell, which can take up a lot of disk space.
The easiest way to clear Bash command history in Ubuntu is to use the UNIX pipe to redirect an empty string to the '.bash_history' file:
echo "" > ~/.bash_history
That means this operation will not clear the history buffer for the current Bash session. To do that, run the following command:
history -cw
Note : You need to rerun this command for every active Bash shell on your current desktop session.
Confirm that your current Bash history is cleared by running the history command without any arguments.
Disable history log in Bash
It is possible to force Bash not to save any command history from any future sessions. This can be useful if you are setting up a shared computer and don't want other users to know the commands you are running on your account.
Start by making sure that the current history buffer in Ubuntu is completely cleared:
history -cw
Open the .bashrc file with your favorite editor:
nano ~/.bashrc
Paste the following lines of code at the end of the .bashrc file:
export HISTSIZE=0 export HISTFILESIZE=0
Note : The HISTSIZE variable determines the number of lines that Bash will keep during a session. Meanwhile, HISTFILESIZE sets the number of lines that the history log file will maintain over time.
Save the .bashrc file, then run the following command to apply the new settings to the current shell session:
source ~/.bashrc
Test the new settings by running the ls command on the current directory, then running the history command again:
ls && history
Delete specific Bash history entries
The history command can also delete specific entries from its cache and history log. This can be useful if you just want to skip some commands instead of deleting the shell's entire history.
Use the history command to find the index number of the command you want to delete. For example, if you want to delete the 7th command in your shell history.
Note : You can search for the specific command you want to delete by passing the history command to grep:
history | grep my-history-command
Run the following command with the index number of the item you want to remove:
history -d 7
Confirm that the history entry is gone by rerunning the history command.
You should read it
- What's new in Ubuntu 18.04 LTS just released?
- How to prolong the life of Ubuntu 18.04 installation with Ubuntu Pro
- What is the difference between Ubuntu Desktop and Ubuntu Server?
- Ubuntu 21.04 users need to update the system ASAP
- 5 things to do after upgrading to Ubuntu 22.04 LTS
- 5 Reasons Ubuntu Cinnamon Is Better Than Other Ubuntu Versions
- 7 reasons to upgrade to Ubuntu 23.04
- Ubuntu 19.10: Roadmap for release & planned features
May be interested
- How to Delete Your Usage History Tracks in Windowsthis wikihow teaches you how to clear the app usage history, file explorer history, search history, and internet browsing history on a windows computer. right-click the taskbar. the taskbar is the bar at the bottom of the screen. doing so...
- Everything you need to know about using Nala on Ubuntunala is an open source, python-based front-end replacement for apt. it performs various functions: parallel download, package update and upgrade, history fetch, autofetch mirror repository and restore installation.
- Instructions to delete Web search history on Chrome, Firefoxinstructions to delete web search history on chrome and firefox to protect privacy while browsing the web.
- How to delete browsing history on iOS9just like a web browser on a computer, every user's web session on ios devices will get back to history and data. this data will increasingly fill up and take up memory on your device. therefore, you need to clear your browsing history to free up memory. if you do not know how to do it, you can refer to our guide below.
- Why is Ubuntu LTS preferred over regular distros?ubuntu is one of the most widely used linux distributions among software developers and other content creators. ubuntu is also used for many servers around the globe.
- What's new in Ubuntu 18.04 LTS just released?ubuntu 18.04 lts code-named bionic beaver has just been officially launched on april 26th. this version is canonical's up to 5 year support period.
- How to prolong the life of Ubuntu 18.04 installation with Ubuntu Proubuntu 18.04, bionic beaver, is one of the most popular distros in use today, but support will end in may 2023, meaning you won't receive updates or security patches anymore.
- How to Clear Address Barinternet privacy involves more than just keeping the data you transmit safe. you may also prefer that others not have evidence of the websites that you visit. this is especially true for those who share a household computer or who must use...
- How to delete search history on CH Play, hide searched contentdo you want to delete your search history on ch play to protect your personal information? free download will guide you through simple steps to quickly clean up your search history.
- What is the difference between Ubuntu Desktop and Ubuntu Server?ubuntu is divided into ubuntu cloud, ubuntu core, ubuntu kylin, ubuntu desktop and ubuntu server. in this article, we will explore all the similarities and differences between ubuntu server and ubuntu desktop.