What Are Environment Variables?
Environment variables are key–value pairs that your shell and applications use to determine behavior, file locations, and settings. You can list all of them with either:Modifying Bash History Size
By default,HISTSIZE=1000 limits your Bash history to 1 000 commands. To increase it for the current session:
Common Environment Variables
Here are a few variables you’ll encounter frequently:| Variable | Description | Example Usage |
|---|---|---|
| HOME | Current user’s home directory | echo $HOME |
| PWD | Current working directory | echo $PWD |
| PATH | Directories to search commands | echo $PATH |
| HISTSIZE | Max number of history entries | echo $HISTSIZE |
saved_file in their own home directory.
Setting Persistent Environment Variables
User-specific variables can go in~/.bashrc or ~/.profile, but for system-wide settings, use /etc/environment.
Line-based syntax only—no shell expansions or functions.
Example entries look like
Example entries look like
KEY="value".Edit /etc/environment
- Open the file with root privileges:
- Add your variable:
- Save and exit.
- Log out and back in, then verify:
Changes in
Always back up
/etc/environment affect all users and services.Always back up
/etc/environment before editing.Automating Commands on Login
To execute commands for every user at login, place shell scripts in/etc/profile.d/. For instance, record the last login time:
- Create a script file:
- Add the following (no shebang required):
- Save and exit.
- Log out and back in, then check:
$HOME and demonstrates how to run tasks automatically upon user login.