Clear Terminal history from Linux, macOS, and Git on Windows

· 2 min read
Clear Terminal history from Linux, macOS, and Git on Windows

If you are a Linux user, macOS or you are using the Git terminal on windows, surely you know that every time we execute a command in the terminal it is stored in the command history.

The history stores the last 500 commands that have been executed in the Terminal, and it is very useful to have this list to be able to access a specific command.

What if we want to delete a command from the history? How do you do it?The first thing we should know is that to show the history of the terminal, we must enter the history command :

See the full history

To see a complete list with the last 500 commands, we must execute in the Terminal:

# Ver historial de comandos
$ history

On the left there is a column with the command history index.

Delete commands from linux terminal

Delete a given command (x)

If we want to eliminate a specific command, we must keep its number that appears on the left side.

# Eliminar el comando X
$ history -d X
Delete linux commands

Delete all history

If we need to delete all the history we simply type in our terminal.

# Eliminar todo el historial
$ history -c
Delete linux commands

View a specified number of commands

Sometimes we need to see only the last, for example, 10 commands executed.