
- Operating System Tutorial
- OS - Home
- OS - Overview
- OS - Components
- OS - Types
- OS - Services
- OS - Properties
- OS - Processes
- OS - Process Scheduling
- OS - Scheduling algorithms
- OS - Multi-threading
- OS - Memory Management
- OS - Virtual Memory
- OS - I/O Hardware
- OS - I/O Software
- OS - File System
- OS - Security
- OS - Linux
- OS - Exams Questions with Answers
- OS - Exams Questions with Answers
- Operating System Useful Resources
- OS - Quick Guide
- OS - Useful Resources
- OS - Discussion
How to Clear BASH Command Line History in Linux?
As we execute various commands they get stored in a file called .bash_history. We can refer to this file later to find all the commands. Sometimes there may be sensitive information in bash commands. To remove the sensitive information, we may remove specific lines from the bass history file or we may remove the entire file itself. In this article we will see both the approaches.
Here we see the .bash_history file.
$ ls -l .bash_history $ cat .bash_
Running the above code gives us the following result −
-rw------- 1 ubuntu ubuntu 6495 Dec 31 19:30 .bash_history
Clearing Individual commands
To clear a specific command from the history we will first find out the line number of the command in the bash history file and then issue the –d option to remove it.
cat -n .bash_history
Running the above code gives us the following result −
u@ubuntu:~$ cat -n .bash_history 1perl -v 2sudo -apt update 3sudo apt -update 4cal 5today 6now 7now() ; .. ..
Lets say we aim to remove the command at line 4 which is the cal command.
$ history
Running the above code gives us the following result −
1 perl -v 2 sudo -apt update 3 sudo apt -update 4 today 5 now 6 now() ; …… ……
Clearing Entire History
We can clear the entire history by using the following command. Here we overwrite the .bash_history file with null.
$cat /dev/null > ~/.bash_history $ cat .bash_history $
As you can see, when we look for the content of .bash_history it is all blank.
- Related Articles
- Preserve Bash History in Multiple Terminal Windows on Linux
- How to create a CPU spike with bash command on Linux?
- How to swap two files in Linux command line?
- Convert XLSX to CSV in Linux with Command Line in Linux
- How to write multiple line strings using Bash with variables on Linux?
- How to clear webview history in android?
- Evaluate XPath in the Linux Command Line
- Best Command Line HTTP Client for Linux
- How to Clear Linux terminal screen?
- Array Operations in Linux bash
- Introduction to Bash Globbing on Linux
- How to Create a New File in Linux from Bash?
- How to use diff Command in Linux
- Find my public ip address from linux command line
- How to send a file as an email attachment using the Linux command line?
