hmm, unset HISTFILE disables recaling previous commands by arrow keys. What to do?
Assistant
You're right - on some systems or Bash configurations, unsetting HISTFILE can interfere with the in-memory history functionality. This is unexpected behavior, but let's work around it.
Here are better approaches that will maintain the arrow key functionality while preventing history from being saved to disk:
1. Set HISTFILE to /dev/null (Recommended)
Instead of unsetting , set it to :
User
why doesn't history -c clear the history?
Assistant
The history -c command should clear the in-memory history list, but there are several reasons why it might appear not to work:
1. History is Immediately Reloaded from HISTFILE
The most common reason is that Bash immediately reloads the history from the HISTFILE after clearing it. This happens in some configurations where history is set to be persistent.
To verify this is happening:
history -c
history
If you see old commands reappear, they're being reloaded from the file.
2.
User
histappend is on. Does it matter?
Assistant
Yes, histappend being on can affect how history behaves, though it shouldn't directly prevent history -c from clearing the in-memory history. However, it does change how Bash handles history files, which might be contributing to your issue.
What histappend Does
When histappend is on:
History is appended to HISTFILE when the shell exits (instead of overwriting it)
In some configurations, it can also cause Bash to read from HISTFILE more frequently
When histappend is :
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Make sure HISTSIZE is set to a positive number (this controls in-memory history):
export HISTSIZE=1000
Testing
Try the /dev/null approach first:
export HISTFILE=/dev/null
export HISTSIZE=1000
Then test:
Run a few commands
Press up arrow - you should be able to recall them
Run history - you should see your commands
Exit the shell and start a new one
Check that the commands weren't saved to your regular history file
If you're still having issues with arrow keys not working, let me know which version of Bash you're using (bash --version) and your operating system, as there might be system-specific configurations affecting this behavior.
Solutions to Actually Clear History
Clear both in-memory and file history:
history -c
history -w
The -w flag writes the (now empty) history to the file, overwriting the old content.
Or clear the file directly:
history -c
> $HISTFILE # This truncates the history file
Or remove the file entirely:
history -c
rm $HISTFILE
3. Check for Multiple History Files
Sometimes there are multiple history files or non-standard configurations:
echo $HISTFILE
ls -la ~/.bash_history*
4. Shell Options Affecting History
Check if certain shell options are set:
shopt | grep hist
Look for options like histappend which might affect behavior.
5. Test in a Clean Environment
Try this sequence to test:
# Start a new bash session with minimal config
bash --norc
# Now test history clearing
echo "test command"
history
history -c
history # Should be empty
6. For Your Use Case
Since you want to prevent saving history to file, combine the approaches:
# Set history file to /dev/null
export HISTFILE=/dev/null
# When you want to clear in-session history
history -c
This way, history -c will clear the in-memory history, and there's no file to reload from since it's set to /dev/null.
If history -c still doesn't work as expected, let me know what output you get from the diagnostic commands above, and we can troubleshoot further.
off
The history file is overwritten with the current session's history when the shell exits
Why This Might Affect history -c
With histappend on, some Bash configurations may:
Periodically sync history between memory and file
Reload history from file after certain operations
Testing the Impact
Try turning off histappend temporarily and see if it changes the behavior:
# Turn off histappend
shopt -u histappend
# Now try clearing history
history -c
history # Check if it's actually empty
For Your Original Goal
Since you want in-session history without saving to file, try this combination:
# Set history file to /dev/null
export HISTFILE=/dev/null
# Turn off histappend (optional, but might help)
shopt -u histappend
# Ensure in-memory history works
export HISTSIZE=1000
With HISTFILE=/dev/null, histappend shouldn't matter much since there's nowhere to append to, but turning it off might prevent any unexpected reloading behavior.
If Problems Persist
You can also check if there are any custom history configurations in your shell:
# Check for PROMPT_COMMAND that might affect history
echo $PROMPT_COMMAND
# Check all history-related variables
set | grep -i hist
Some systems have PROMPT_COMMAND set to save history after each command, which could interfere with your goals.