← Digital forensicssee how much your shell secretly remembers

see how much your shell secretly remembers

$wc -l ~/.bash_history

see how much your shell secretly remembers

open a terminal right now and run one command. you're about to find out your shell has been keeping a diary this whole time, and it's not exactly locked up.

wc -l ~/.bash_history

that's it. that's the whole command. and depending on how long you've had this machine, the number that comes back might genuinely surprise you. a few hundred lines. a few thousand. some of you are gonna see five digits and question every life choice that led here.

what's actually happening

wc stands for word count, and the -l flag tells it to count lines instead of words or characters. ~/.bash_history is a plaintext file sitting quietly in your home directory. every time you close a terminal session (or hit a certain history size limit), bash dumps whatever you typed into that file. not encrypted. not hashed. just sitting there as plain text, readable by anyone with access to your account or that file.

so that one line is really just "count how many commands are sitting in my personal, unprotected activity log."

why this matters more than people think

your bash history isn't just a list of commands, it's a timeline of your habits. if you've ever typed a password directly into a command (curl requests, mysql logins, api calls with tokens baked in), that stuff might be sitting in this file right now, in plaintext, forever, until someone or something reads it.

this is also exactly why forensic investigators and, yes, attackers who've already gotten a foothold on a box, love checking this file. it tells them what tools you use, what servers you connect to, what your workflow looks like, and sometimes literally hands them credentials. you don't need malware for this. you just need read access.

actually look at what's in there

the line count is just the appetizer. go read the actual contents:

cat ~/.bash_history

or if you want to search for the scary stuff specifically, grep for common leak patterns:

grep -iE "password|token|secret|api_key|-p " ~/.bash_history

if that comes back empty, congrats, you've been disciplined. if it doesn't, you now know exactly what needs to get cleaned up and which credentials need rotating immediately, because if it's in your history file, treat it as compromised.

how to actually lock this down

first, clear what's already there if it's full of sensitive stuff:

history -c
rm ~/.bash_history

but clearing it once doesn't fix the habit, it just resets the clock. here's what actually protects you going forward:

stop typing secrets directly into commands. use environment variables, config files with restricted permissions, or a secrets manager instead of pasting a password after a -p flag.

add a space before any command you don't want logged. most shells respect HISTCONTROL=ignorespace, meaning a command that starts with a literal space won't get saved. add this to your ~/.bashrc:

export HISTCONTROL=ignoreboth

this ignores duplicate commands and anything prefixed with a space.

lock down the file permissions so only you can read it:

chmod 600 ~/.bash_history

and if you're on a shared or high risk machine, consider disabling history entirely for sensitive sessions:

set +o history

turn it back on later with set -o history when you're done.

the takeaway

your shell isn't spying on you, it's just doing exactly what it was told to do, keep a record so you can scroll up and reuse old commands. the problem is nobody warns you that "record" means plaintext file, permanently, unless you clean it up yourself. run the command, check your line count, grep for leaked secrets, and build the habit of keeping passwords out of your terminal in the first place. your future self doing an incident response at 2am will thank you.

watch the reel ↗
the weekly drop

one command a week that makes you harder to hack.

a single tool, explained in plain english, every week. straight to your inbox.

no spam. one email a week. unsubscribe anytime.