Enhancing Skills

Important environment variables commonly used in Linux

VariableDescription
HOMEPath to the current user’s home directory.
PATHList of directories that the shell searches for executable files.
USERUsername of the currently logged-in user.
SHELLPath to the current user’s default shell.
PWDCurrent working directory.
OLDPWDPrevious working directory, before the last directory change.
LANGDefault system language and locale settings.
EDITORDefault text editor used by commands like crontab -e.
HISTSIZENumber of commands to remember in the command history.
HISTFILEPath to the file where the command history is stored (e.g., ~/.bash_history).
LOGNAMEUsername of the current user (same as USER).
MAILPath to the file where user mail is stored.
TERMTerminal type used for communication between the terminal and the system.
TMPDIRDirectory for temporary files used by programs.
PS1Primary prompt string for the shell. Defines the appearance of the command prompt.
PS2Secondary prompt string for the shell, used for multi-line commands.
LANGUAGELanguage preferences for localization, often used alongside LANG.
LC_ALLOverrides all other locale settings, used for setting language and regional preferences.
SSH_AUTH_SOCKPath to the Unix domain socket used by the SSH agent for communication.
SSH_CLIENTContains the IP address, incoming port, and outgoing port of the SSH client session.
SSH_CONNECTIONInformation about the SSH connection, including client IP, client port, server IP, and server port.
HOSTNAMEThe system’s hostname.
DISPLAYUsed to specify the display server for graphical applications on a networked system.
XAUTHORITYLocation of the X server authority file, used for X session authentication.
TZTime zone setting for the system.
LD_LIBRARY_PATHList of directories where the system looks for dynamic libraries.
MANPATHDirectories that contain manual pages, searched by the man command.
SHLVLShell level, indicating the number of nested shell sessions.
BASH_VERSIONVersion of the Bash shell.
PROMPT_COMMANDCommand to be executed before the prompt is displayed, often used to update the terminal prompt.
HOSTTYPEDescribes the type of hardware running the system (e.g., x86_64).
OSTYPEDescribes the operating system (e.g., linux-gnu).
MACHTYPEDescribes the machine hardware and operating system (e.g., x86_64-pc-linux-gnu).
UIDUser ID of the current user.
GIDGroup ID of the current user.
PWDCurrent working directory.
CDPATHDirectories to search when using the cd command.
IFSInternal Field Separator, which determines how the shell splits input text into words (default is space, tab, newline).
HISTCONTROLControls how the command history is saved, with options like ignorespace and ignoredups.
HISTIGNOREList of patterns to exclude from the command history.
HISTTIMEFORMATFormat 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.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.