Important environment variables commonly used in Linux
August 12th, 2024 10:14 AM Mr. Q Categories: Command
Variable | Description |
---|---|
HOME | Path to the current user’s home directory. |
PATH | List of directories that the shell searches for executable files. |
USER | Username of the currently logged-in user. |
SHELL | Path to the current user’s default shell. |
PWD | Current working directory. |
OLDPWD | Previous working directory, before the last directory change. |
LANG | Default system language and locale settings. |
EDITOR | Default text editor used by commands like crontab -e . |
HISTSIZE | Number of commands to remember in the command history. |
HISTFILE | Path to the file where the command history is stored (e.g., ~/.bash_history ). |
LOGNAME | Username of the current user (same as USER ). |
MAIL | Path to the file where user mail is stored. |
TERM | Terminal type used for communication between the terminal and the system. |
TMPDIR | Directory for temporary files used by programs. |
PS1 | Primary prompt string for the shell. Defines the appearance of the command prompt. |
PS2 | Secondary prompt string for the shell, used for multi-line commands. |
LANGUAGE | Language preferences for localization, often used alongside LANG . |
LC_ALL | Overrides all other locale settings, used for setting language and regional preferences. |
SSH_AUTH_SOCK | Path to the Unix domain socket used by the SSH agent for communication. |
SSH_CLIENT | Contains the IP address, incoming port, and outgoing port of the SSH client session. |
SSH_CONNECTION | Information about the SSH connection, including client IP, client port, server IP, and server port. |
HOSTNAME | The system’s hostname. |
DISPLAY | Used to specify the display server for graphical applications on a networked system. |
XAUTHORITY | Location of the X server authority file, used for X session authentication. |
TZ | Time zone setting for the system. |
LD_LIBRARY_PATH | List of directories where the system looks for dynamic libraries. |
MANPATH | Directories that contain manual pages, searched by the man command. |
SHLVL | Shell level, indicating the number of nested shell sessions. |
BASH_VERSION | Version of the Bash shell. |
PROMPT_COMMAND | Command to be executed before the prompt is displayed, often used to update the terminal prompt. |
HOSTTYPE | Describes the type of hardware running the system (e.g., x86_64 ). |
OSTYPE | Describes the operating system (e.g., linux-gnu ). |
MACHTYPE | Describes the machine hardware and operating system (e.g., x86_64-pc-linux-gnu ). |
UID | User ID of the current user. |
GID | Group ID of the current user. |
PWD | Current working directory. |
CDPATH | Directories to search when using the cd command. |
IFS | Internal Field Separator, which determines how the shell splits input text into words (default is space, tab, newline). |
HISTCONTROL | Controls how the command history is saved, with options like ignorespace and ignoredups . |
HISTIGNORE | List of patterns to exclude from the command history. |
HISTTIMEFORMAT | Format for timestamps in the history file, useful for tracking when commands were executed. |
Examples
Check Environment Variables:
printenv
Print a Specific Variable:
echo $HOME
Set an Environment Variable Temporarily:
export VAR_NAME=value
Set an Environment Variable Permanently:
Add the export command to your shell’s startup file, e.g., ~/.bashrc
or ~/.bash_profile
:
echo 'export VAR_NAME=value' >> ~/.bashrc
source ~/.bashrc
Understanding and managing these environment variables allows for greater control over the behavior of the system and applications, enabling customization of the environment to suit specific needs.