Skip to content

Instantly share code, notes, and snippets.

@leommoore
Last active July 2, 2023 00:42
Show Gist options
  • Save leommoore/30d77dfc78407a894546 to your computer and use it in GitHub Desktop.
Save leommoore/30d77dfc78407a894546 to your computer and use it in GitHub Desktop.
Linux Environment Variables

#Linux Environment Variables

##Current Environment Variables You can list all the currennt environment variables using the env command.

XDG_VTNR=7
SSH_AGENT_PID=2030
XDG_SESSION_ID=c2
XDG_GREETER_DATA_DIR=/var/lib/lightdm-data/leo
SELINUX_INIT=YES
CLUTTER_IM_MODULE=xim
SESSION=ubuntu
GPG_AGENT_INFO=/run/user/1000/keyring-8aikcm/gpg:0:1
TERM=xterm
VTE_VERSION=3409
XDG_MENU_PREFIX=gnome-
SHELL=/bin/bash
SSH_AGENT_LAUNCHER=upstart
WINDOWID=75497483
UPSTART_SESSION=unix:abstract=/com/ubuntu/upstart-session/1000/1899
GNOME_KEYRING_CONTROL=/run/user/1000/keyring-8aikcm
GTK_MODULES=overlay-scrollbar:unity-gtk-module
USER=leo
NVM_DIR=/usr/sbin
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:
LIBGL_DRIVERS_PATH=/usr/lib/fglrx/dri:/usr/lib/x86_64-linux-gnu/dri:/usr/lib/dri:/usr/lib32/fglrx/dri:/usr/lib/i386-linux-gnu/dri
LD_LIBRARY_PATH=/usr/lib32
XDG_SESSION_PATH=/org/freedesktop/DisplayManager/Session0
XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0
SSH_AUTH_SOCK=/run/user/1000/keyring-8aikcm/ssh
SESSION_MANAGER=local/NDX0001:@/tmp/.ICE-unix/2105,unix/NDX0001:/tmp/.ICE-unix/2105
DEFAULTS_PATH=/usr/share/gconf/ubuntu.default.path
XDG_CONFIG_DIRS=/etc/xdg/xdg-ubuntu:/usr/share/upstart/xdg:/etc/xdg
DESKTOP_SESSION=ubuntu
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
QT_IM_MODULE=ibus
QT_QPA_PLATFORMTHEME=appmenu-qt5
NVM_NODEJS_ORG_MIRROR=http://nodejs.org/dist
PWD=/home/leo
JOB=dbus
XMODIFIERS=@im=ibus
EDITOR=nano
GNOME_KEYRING_PID=1856
LANG=en_IE.UTF-8
GDM_LANG=en_US
MANDATORY_PATH=/usr/share/gconf/ubuntu.mandatory.path
NODE_PATH=/usr/lib/nodejs:/usr/lib/node_modules:/usr/share/javascript
UBUNTU_MENUPROXY=1
COMPIZ_CONFIG_PROFILE=ubuntu
IM_CONFIG_PHASE=1
GDMSESSION=ubuntu
SESSIONTYPE=gnome-session
SHLVL=1
HOME=/home/leo
XDG_SEAT=seat0
LANGUAGE=en_IE:en
GNOME_DESKTOP_SESSION_ID=this-is-deprecated
LOGNAME=leo
COMPIZ_BIN_PATH=/usr/bin/
DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-VPyqpJ78Sb
XDG_DATA_DIRS=/usr/share/ubuntu:/usr/share/gnome:/usr/local/share/:/usr/share/
QT4_IM_MODULE=xim
LESSOPEN=| /usr/bin/lesspipe %s
INSTANCE=
TEXTDOMAIN=im-config
XDG_RUNTIME_DIR=/run/user/1000
DISPLAY=:0
XDG_CURRENT_DESKTOP=Unity
GTK_IM_MODULE=ibus
LESSCLOSE=/usr/bin/lesspipe %s %s
TEXTDOMAINDIR=/usr/share/locale/
XAUTHORITY=/home/leo/.Xauthority
COLORTERM=gnome-terminal
_=/usr/bin/env
OLDPWD=/home/leo/Projects/ReceiptAnalysis
leo@NDX0001:~$cd /home
leo@NDX0001:/home$env
XDG_VTNR=7
SSH_AGENT_PID=2030
XDG_SESSION_ID=c2
XDG_GREETER_DATA_DIR=/var/lib/lightdm-data/leo
SELINUX_INIT=YES
CLUTTER_IM_MODULE=xim
SESSION=ubuntu
GPG_AGENT_INFO=/run/user/1000/keyring-8aikcm/gpg:0:1
TERM=xterm
VTE_VERSION=3409
XDG_MENU_PREFIX=gnome-
SHELL=/bin/bash
SSH_AGENT_LAUNCHER=upstart
WINDOWID=75497483
UPSTART_SESSION=unix:abstract=/com/ubuntu/upstart-session/1000/1899
GNOME_KEYRING_CONTROL=/run/user/1000/keyring-8aikcm
GTK_MODULES=overlay-scrollbar:unity-gtk-module
USER=leo
NVM_DIR=/usr/sbin
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:
LIBGL_DRIVERS_PATH=/usr/lib/fglrx/dri:/usr/lib/x86_64-linux-gnu/dri:/usr/lib/dri:/usr/lib32/fglrx/dri:/usr/lib/i386-linux-gnu/dri
LD_LIBRARY_PATH=/usr/lib32
XDG_SESSION_PATH=/org/freedesktop/DisplayManager/Session0
XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0
SSH_AUTH_SOCK=/run/user/1000/keyring-8aikcm/ssh
SESSION_MANAGER=local/NDX0001:@/tmp/.ICE-unix/2105,unix/NDX0001:/tmp/.ICE-unix/2105
DEFAULTS_PATH=/usr/share/gconf/ubuntu.default.path
XDG_CONFIG_DIRS=/etc/xdg/xdg-ubuntu:/usr/share/upstart/xdg:/etc/xdg
DESKTOP_SESSION=ubuntu
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
QT_IM_MODULE=ibus
QT_QPA_PLATFORMTHEME=appmenu-qt5
NVM_NODEJS_ORG_MIRROR=http://nodejs.org/dist
PWD=/home
JOB=dbus
XMODIFIERS=@im=ibus
EDITOR=nano
GNOME_KEYRING_PID=1856
LANG=en_IE.UTF-8
GDM_LANG=en_US
MANDATORY_PATH=/usr/share/gconf/ubuntu.mandatory.path
NODE_PATH=/usr/lib/nodejs:/usr/lib/node_modules:/usr/share/javascript
UBUNTU_MENUPROXY=1
COMPIZ_CONFIG_PROFILE=ubuntu
IM_CONFIG_PHASE=1
GDMSESSION=ubuntu
SESSIONTYPE=gnome-session
SHLVL=1
HOME=/home/leo
XDG_SEAT=seat0
LANGUAGE=en_IE:en
GNOME_DESKTOP_SESSION_ID=this-is-deprecated
LOGNAME=leo
COMPIZ_BIN_PATH=/usr/bin/
DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-VPyqpJ78Sb
XDG_DATA_DIRS=/usr/share/ubuntu:/usr/share/gnome:/usr/local/share/:/usr/share/
QT4_IM_MODULE=xim
LESSOPEN=| /usr/bin/lesspipe %s
INSTANCE=
TEXTDOMAIN=im-config
XDG_RUNTIME_DIR=/run/user/1000
DISPLAY=:0
XDG_CURRENT_DESKTOP=Unity
GTK_IM_MODULE=ibus
LESSCLOSE=/usr/bin/lesspipe %s %s
TEXTDOMAINDIR=/usr/share/locale/
XAUTHORITY=/home/leo/.Xauthority
COLORTERM=gnome-terminal
_=/usr/bin/env
OLDPWD=/home/leo

##Prompt The bash prompt is in $PS1.

echo $PS1
\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$

Typical values can include:

\a     an ASCII bell character (07)
\d     the date in "Weekday Month Date" format (e.g., "Tue May 26")
\D{format}
       the format is passed to strftime(3) and the result  is  inserted  into  the  prompt
       string;  an  empty  format  results  in a locale-specific time representation.  The
       braces are required
\e     an ASCII escape character (033)
\h     the hostname up to the first `.'
\H     the hostname
\j     the number of jobs currently managed by the shell
\l     the basename of the shell's terminal device name
\n     newline
\r     carriage return
\s     the name of the shell, the basename of $0 (the portion following the final slash)
\t     the current time in 24-hour HH:MM:SS format
\T     the current time in 12-hour HH:MM:SS format
\@     the current time in 12-hour am/pm format
\A     the current time in 24-hour HH:MM format
\u     the username of the current user
\v     the version of bash (e.g., 2.00)
\V     the release of bash, version + patch level (e.g., 2.00.0)
\w     the current working directory, with $HOME abbreviated with a tilde (uses the  value of the PROMPT_DIRTRIM variable)
\W     the basename of the current working directory, with $HOME abbreviated with a tilde
\!     the history number of this command
\#     the command number of this command
\$     if the effective UID is 0, a #, otherwise a $
\nnn   the character corresponding to the octal number nnn
\\     a backslash
\[     begin  a sequence of non-printing characters, which could be used to embed a terminal control sequence into the prompt
\]     end a sequence of non-printing characters

To set the variable you do not need to prefix it with $.

PS1="\h:\W \u [\t] \$"

To ensure that the variables are available in each session then they need to be added to the .bashrc. Note: when you create or update a variable in a shell it does not automatically become available to all programs running in the shell. You need to export it.

export EDITOR=nano

##PATH The PATH is probably one of the most important variables. To add something (eg ~/bin) to the PATH the best way is to use:

PATH="$PATH:~/bin"

This will take the contents of $PATH and add the additional text (ie :~/bin, where : is the separator character). You can add this to your .bashrc by appending it to the end using:

echo 'PATH="$PATH:~/bin"' >> ~/.bashrc

You should always add it to the end of your .bashrc to keep it separate and to ensure that you don't overwrite system commands.

@okierie
Copy link

okierie commented Nov 8, 2016

I have a php file contains print_r($_SERVER) and I execute it via terminal php phpfile.php. The output is exactly the same with these linux environment variables. Do you know why? Is it because of I don't execute it via webserver(apache,nginx)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment