← Back to list

Why Your Terminal Forgets Everything the Moment You Close It, and the One Fix That Changes That

Here’s why that happens and how to stop it permanently

Sabit in Bash_DevOps_AI · 2026-06-26 07:12 · 8 claps · 3.7 min read paywalled
#devops #linux #bash #programming #coding
Open on Medium ↗
Wiki topics: 💻 · Programming ☁️ · DevOps & Cloud 🔓 · Open Source

Why Your Terminal Forgets Everything the Moment You Close It, and the One Fix That Changes That

Here’s why that happens and how to stop it permanently

Photo by Lukas on Unsplash

Photo by Lukas on Unsplash

You set up something useful in your terminal.

Maybe a shortcut that runs a long command in three letters. It works perfectly.

You close the terminal and open it again. Everything is gone.

This is one of the first frustrating things people hit when they start using the terminal regularly. It feels like a bug. It isn’t. It’s how the system is designed, and once you understand why, the fix becomes obvious.

Every terminal session starts completely fresh

When you open a terminal window, your shell starts as a new process. It loads a base environment, gives you a prompt, and waits for commands.

When you close it, that process ends. Everything you set inside it, variables, aliases, custom settings, lived only in the memory of that process. When the process dies, they go with it.

This is intentional. A terminal session is meant to be a clean, predictable environment every time. If every change you ever made persisted automatically, sessions would accumulate settings from months or years of work, conflicts would build up, and debugging anything would become very difficult very fast.

The tradeoff is that nothing survives by default. Every session starts from scratch.

The one fix that changes this permanently

Your shell has a configuration file that runs automatically every time a new session starts. Think of it as a script that loads before your prompt even appears.

Whatever you put in it becomes part of every session you ever open, automatically, without you doing anything after the first time.

For most people using Bash, this file is called .bashrc and it lives in your home folder. For people using Zsh, the default shell on modern Macs, it's .zshrc. Same idea, slightly different name.

You can open it directly from the terminal.

nano ~/.bashrc

Or if you’re on Zsh:

nano ~/.zshrc

This file may already have content in it. Some distributions populate it with default settings out of the box. Scroll to the bottom and add whatever you want to persist from there.

What you can actually save in there

Aliases. An alias is a shortcut. If you find yourself typing the same long command repeatedly, you can assign it to something shorter.

alias update='sudo apt update && sudo apt upgrade -y'

Now typing update in any future session runs that full command automatically.

alias ll='ls -lah'

This makes ll run ls with long format, hidden files, and human-readable file sizes every time. Many distributions ship with this already set, but if yours doesn't, adding it yourself takes five seconds.

Environment variables. These are values your shell and the programs it runs can reference by name. If a tool you use needs to know a project path, an API key, or a configuration setting, you can define it here once.

export PROJECT_DIR="$HOME/projects/myapp"

Now $PROJECT_DIR is available in every session without having to set it again.

PATH additions. The PATH variable is a list of directories your shell searches when you type a command. If you install a tool and the terminal says "command not found," the tool's location probably isn't in your PATH. Adding it here fixes that permanently.

export PATH="$HOME/.local/bin:$PATH"

This adds ~/.local/bin to your PATH in every future session. Replace the path with wherever your tool actually lives.

A prompt you can actually read. The default terminal prompt on many systems is either too minimal or cluttered with information you don’t need.

You can customize exactly what it shows, current directory, git branch, time, anything, by setting the PS1 variable in your config file.

This is a rabbit hole on its own, but even a small change can make the prompt noticeably more useful.

After you edit the file, one extra step

Saving the file is not enough on its own. The changes don’t apply to your current session automatically. You either need to open a new terminal window, or tell your current session to reload the file.

source ~/.bashrc

This runs the file inside your current session, making all the new settings active immediately without closing anything.

The part most people miss

.bashrc runs for interactive non-login shells.

But there's a related file called .bash_profile or .profile that runs for login shells, like when you connect remotely via SSH or log in directly without a graphical desktop.

If you’re adding something and it isn’t showing up when you’d expect, the distinction between these two files is usually why. A common solution is to have .bash_profile simply load .bashrc itself, so everything stays in one place regardless of which type of session starts.

if [ -f ~/.bashrc ]; then
    source ~/.bashrc
fi

Adding that to .bash_profile means your settings load consistently whether the session is interactive, a login shell, or both.

What this actually changes

Before knowing about this file, people tend to either redo their setup every session or avoid customizing their terminal at all because it feels pointless. After, the terminal starts feeling like something that remembers who you are and how you work.

That is a small shift in practice. It compounds over time.

Thanks for reading! I left a six-figure smart contract auditing career to learn Linux, Python, and AI engineering from scratch. I share my raw learning updates and one actionable terminal trick every Wednesday in my newsletter, Terminal to AI. **Join the journey for free here.**


메타데이터
post_id
13a94365de36
slug
why-your-terminal-forgets-everything-the-moment-you-close-it-and-the-one-fix-that-changes-that-13a94365de36
url
https://medium.com/my-lifes-mirrow/why-your-terminal-forgets-everything-the-moment-you-close-it-and-the-one-fix-that-changes-that-13a94365de36
canonical_url
https://medium.com/my-lifes-mirrow/why-your-terminal-forgets-everything-the-moment-you-close-it-and-the-one-fix-that-changes-that-13a94365de36
author_url
https://medium.com/@tibas
status
ok
fetched_at
2026-06-27 18:23:53