Linux/Bash: Clear Command Line Cache

This post will guide you how to clear out all command history or cache from bash shell prompt in Linux.

Clear Command Line Cache


The bash shell will store all command the recently-executed into ~/.bash_history. So if you want to clear command cache in bash shell, you just need to remove this file or empty this file. Or you can also execute the history command with –c option.

Type any of the following command:

#echo “” >~/.bash_history

Or

#history –c

If you want to clear the history of a single command from command cache, you need to run the history command along with –d option and then pass to the line number. Like this:

#history –d 100

It will delete the command line 100 from bash shell history

Execute command from Bash History


The history command will display all command list that you have executed, and if you want to execute commands from bash history, you can use the exclamation mark ! character with the line number from the command history in bash shell.

For example, the line number of one command is 100, and you want to re-run this command, just type the following command:

# !100

Execute Last command From Bash History


If you want to run the last command from bash history, you just need to type double exclamation marks, type:

# !!

Outputs:

root@ubuntu-dev:~# uname -a
Linux ubuntu-dev 4.10.0-28-generic #32~16.04.2-Ubuntu SMP Thu Jul 20 10:19:48 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

root@ubuntu-dev:~# !!
uname -a
Linux ubuntu-dev 4.10.0-28-generic #32~16.04.2-Ubuntu SMP Thu Jul 20 10:19:48 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

 

 

 

You might also like:

Sidebar



back to top