In this simple tutorial, we will show you how to view and clear the history of commands typed into the Terminal app of your Mac.
Why you would want to do that
Viewing your command history in macOS 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 up to 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 usage from being seen by other users of your computer, then clearing it will be an effective way of doing so.
View your Terminal command history on Mac
This command will let you see all the commands entered since the most recent clear command was used:
1) Launch the Terminal app, enter the following command, and then press the return key on your keyboard.
history
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, paste it back into the Terminal window, and press the return key on your keyboard to run it.
Clear Mac’s Terminal command history
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, enter the following command, and press the return key from your keyboard to initiate it.
history -c
If history -c
does not work for you, use:
history -p
2) Your command line history is cleared, and you can perform the “history” command again immediately afterward to verify that your command line history no longer exists. Using history
will just show one result, which is history itself.
Other Terminal tips: