
Used with os.system, this makes a nice one-liner: import os os.system ('cls' if os. Commands must be executed/queued for execution otherwise they do nothing. Run the clear at the bottom of the terminal prompt.
#Clear trminal command full
In other words, if you want to use a command that you don’t want to include in the shell history, simply type a space or a tab first and then type the command.Īs a last trick ─ one that I do not use myself, but it’s a possibility ─ if you want your shell history to have only a certain number of commands in it but no other ones, you can “freeze” it in place by making it immutable… chattr +i ~/.bash_historyĭo however bear in mind that this also means that the file can no longer be renamed or deleted. A simple and cross-platform solution would be to use either the cls command on Windows, or clear on Unix systems. A command that clears the terminal screen buffer. Let's assume that your terminal is full of commands and output as shown below.

Launch the Terminal app from Applications > Utilities or search for it via Spotlight.
#Clear trminal command mac
… in every open shell environment as well. We're here to help with a detailed cheat sheet of Mac Terminal commands you can use to unlock enhanced productivity on your system.

#Clear trminal command windows
Other running shell windows will however still have their command history too, so you’d need to run… history -c Type 'rm (filename)' in the Terminal to remove a file on Linux. It works because '\e' is the ESCape code, and the 'ESC c' sequence sends. If you are instead running zsh, then I don’t know where it keeps its history file or what name it has ─ it’ll probably be something easily identifiable, though ─ but more importantly, I seem to have read that zsh shares its history across all running shells, probably through some common memory page.Īnyway, the command I’ve shown you above will clear your command history in the running shell window and will truncate the history file. Apparently running the following command does exactly that: printf '\ec' It clears the terminal and the scroll buffer. And the second command, in turn, truncates the history file, ~/.bash_history. The & is a logical “ AND” operator, meaning that the second command will be executed only if the first command was successful.

However, if you want to completely clean out the history of one particular running shell and of any new shells that will be started, the best approach would be… history -c & > ~/.bash_historyĮxplaining the syntax, the first command ─ which you already know ─ empties the command history of the running shell. The way to clear out the history of the running shell ─ but this will not touch the history of newly started shells, nor of other already running shells ─ is… history -c
