If you’ve ever wanted to see a running history of all the Terminal commands you’ve used on your Mac, or that you suspect another user of your Mac has used, there is a simple command you can run.
In this tutorial, we’ll show you how you can view your Terminal command history, as well as clear your command history from being seen by unwanted eyes.
Why to view and clear your command history
Viewing your command history in OS X could be a useful feature if you want to see a long command you’ve used recently that you just can’t remember; this makes it easy to simply copy and paste the command and re-use it. Seeing your command history can also be useful if you have other users on your Mac and you want to see what kinds of things they’re doing with the Terminal app.
As for clearing your command line history, if you’re using Terminal on an institutional machine and need to hide commands you’re using from your administrator, or you want to increase your own privacy and keep your Terminal usage from being seen by other users of your computer, then clearing it will be an effective way of doing so.
How to view your command history in Terminal
The first thing we’ll show you is how to view your command line history in Terminal. This command will let you see all the commands entered since the most recent clear command was used.
To view your command history in the Terminal app, follow these steps:
1) Launch the Terminal app and enter the following command and then press the Return key on your keyboard.
2) Your entire command line history up to the last clear will be displayed.
At this point, you’re free to scroll up and down in the Terminal window to see what kinds of commands have been used. If at any point you see a command you want to re-use, you can simply highlight it, copy it, and paste it back into the Terminal window and press the Return key on your keyboard to run it.
How to clear your command history in Terminal
If you don’t want someone using the above steps to see what commands you’ve been using in your Terminal app, then you can cover your tracks by clearing your command line history. This is done with another simple command, so just follow these steps:
1) Launch the Terminal app and enter the following command, then press the Return key from your keyboard to initiate it.
2) Your command line history is cleared, and you can perform the “history” command again immediately afterwards to verify that your command line history no longer exists:
Viewing and clearing your Terminal command line history is easy, and it’s a great way to keep track of your commands and to cover your tracks if you have to.
These may also interest you:
If you found this tutorial helpful, let us know in the comments below!