Forrest logo
back to the history tool

history:tldr:7b6d0

history: Overwrite history file with history of current `bash` shell (often combined with `history -c` to purge history).
$ history -w
try on your machine

The command "history -w" is used in a Unix-like operating system to write the current session's command history to a file.

In Unix-like systems, the command history feature keeps a record of all the commands executed by a user in a specific session. This history is stored in memory and is accessible through the "history" command.

However, if the session ends or the system is restarted, the command history is typically lost. Therefore, the "history -w" command is used to save the current command history to a file, typically in the user's home directory. This ensures that the command history will persist even after the session ends.

Once executed, the "history -w" command writes the current command history to a file, often called .bash_history. This file contains a list of all previously executed commands, along with their respective command numbers. By default, it is located in the user's home directory and it is usually a hidden file.

By saving the command history, a user can review and reuse previously executed commands by using the "history" command or by examining the .bash_history file manually. Additionally, it allows users to maintain a record of their actions that can be useful for auditing or troubleshooting purposes.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the history tool