Shell commands history [Linux]

Here is a quick tip for those who use Linux and in particular those who use shell/terminal often. We all know that terminal remembers all your past commands and you can navigate to and fro using arrow keys. But what if you want to use a particular command which you used long back. It involves a lot of navigation.

But luckily all commands are stored in a text file called ".bash_history" which is located in the home folder of the user (ex: /home/adithya).  Its a hidden and system file by default. Normally all linux file managers shows the hidden files by pressing CTRL + H.

So, just open that file in text editor and you can see all commands that you have typed in.

In case you want to clear all your command history, first delete the ".bash_history" file by typing command
rm ~/.bash_history
In addition, if you want to clear the buffer history (Command history remains active after history file deletion until the current terminal session is closed ), then issue command :
history -c
This will reset the terminal command history.

In case you wish to copy/transfer the command history from one system / user to another, just copy the ".bash_history" file and overwrite it in the target user folder. 

About This Blog

There is something for everyone. !! A tech blog on various topics. Let it be devops, programming etc; we have it all covered here in layman terms :)

Total Pageviews

Back to TOP