Bash 명령어 히스토리 삭제

If you have been using the bash shell in Linux for a while, you might have noticed that it keeps a history of all the commands you have typed. While this can be helpful for quickly accessing previously executed commands, there may be times when you want to delete your command history for security or privacy reasons. In this blog post, we will explore different methods to clear your bash command history.

Method 1: Using the history command

The simplest way to delete your command history is by using the history command provided by bash. Open your terminal and follow these steps:

  1. Type history -c and press Enter. This command clears the entire command history in your current session.
  2. To clear the history permanently, you need to clear the contents of the .bash_history file in your home directory. Run the command > ~/.bash_history to remove all the stored history.

Please note that this method will only delete the history of your current session and the changes are not permanent until you clear the .bash_history file.

Method 2: Modifying the HISTSIZE value

The HISTSIZE environment variable determines the maximum number of commands that will be saved in your bash history. By modifying this variable, you can limit the number of commands or completely disable history saving.

  1. Open your terminal and enter the command export HISTSIZE=0 to disable history saving. This will prevent any new commands from being added to the history.
  2. If you want to limit the history to a certain number of commands, use the command export HISTSIZE=<number>, replacing <number> with the desired limit.

Remember that modifying the HISTSIZE variable will not delete any existing command history, it will only affect future command entries.

Method 3: Modifying the .bashrc file

The .bashrc file is a script that runs every time you launch a new bash session. By modifying this file, you can configure your bash history settings permanently.

  1. Open the .bashrc file using a text editor. Typically, this file is located in your home directory. You can open it with the command nano ~/.bashrc.
  2. Scroll down and find the line that starts with HISTSIZE=. Modify the value to your desired limit or set it to 0 to disable history saving completely.
  3. Save the changes and exit the text editor.

After modifying the .bashrc file, the changes will take effect the next time you open a new terminal session.

Conclusion

Clearing your bash command history is a straightforward process that you can accomplish using different methods. Whether you want to clear the history temporarily for the current session or permanently disable it, consider the options mentioned in this post. Remember to be cautious when dealing with command history, especially if you are concerned about privacy or security.