Clear Terminal History 1


Clear Terminal History


This is a rather simple tip that will allow you to clear Terminal history either selectively or every entry within the terminals history file. When you type in Terminal history it will show you every single entry you have made. Previously I have mentioned how you can change the history size to suit, however if it is becoming rather large, or you want to remove entries that you do not want other people to access, such as a super secret location you don’t want other people to find out about, it is worth removing entries.

To clear every entry in Terminals history type the following into the command prompt.

history -c

Within a blink of an eye, the history will be cleared, not that you cannot reverse this command so ensure you really want to clear you history. Now when you press the up button on your keyboard, no entries will be displayed.

If clearing the history is a bit to extreme, or there is just one entry you want to remove, such as an incorrect command from your list you do not want to repeat it is better to selectively remove the entry. This is done by modifying .bash_history. It is a hidden file located in your User directory that is accessed every time Terminal writes it’s history to disk. In a new Terminal prompt (to ensure you are at your User folder by default), type the following:

ls -a

This will show you all of the hidden files and folder. If you look through the list you should notice a file called .bash_history. To modify this file type the following:

nano .bash_history

You can now use the nano text editor to modify each line. If you don’t know how to use the nano text editor, the nano editor homepage is a good place to look, or you would rather use TextEdit, instead type the following into Terminal:

open .bash_history

This will open up TextEdit, now you can modify the file a lot quicker and easier. Delete the lines as you see fit. When you have finished simply save the file in TextEdit and restart the Terminal app to ensure the change has taken effect.

It is only a simple change but it can be useful if there is an incorrect command that you want to remove, I find I use the history to quickly select commands and it is always annoying when you have to scroll past incorrect commands. If you want to learn more about Mac Terminal commands, either look through the Terminal commands section on this site or read a recommended Terminal Book from Amazon.

P.S Sorry for the long time between the last post, this last year was really busy and finding time to work on this site was a bit problematic.

If you want to keep up with the latests post from Mac Tricks And Tips I recommend you subscribe to the RSS Feed.

Where To Next?

  • Subscribe To Mac Tricks And Tips