printenv Command in Linux with Examples

This tutorial explains Linux “printenv” command, options and its usage with examples.

printenv – print all or part of environment

Description :

printenv prints the values of the specified environment VARIABLE(s). If no VARIABLE is specified, print name and value pairs for them all.

Usage :

printenv [VARIABLE]…
printenv OPTION

advertisement
advertisement

Options :

-0, –null

end each output line with 0 byte rather than newline
–help
display help and exit

A list of the commonly used variables in Linux :

System Variable Meaning To View Variable Value Type
BASH_VERSION Holds the version of this instance of bash. echo $BASH_VERSION
HOSTNAME The name of the your computer. echo $HOSTNAME
CDPATH The search path for the cd command. echo $CDPATH
HISTFILE The name of the file in which command history is saved. echo $HISTFILE
HISTFILESIZE The maximum number of lines contained in the history file. echo $HISTFILESIZE
HISTSIZE The number of commands to remember in the command history. The default value is 500. echo $HISTSIZE
HOME The home directory of the current user. echo $HOME
IFS The Internal Field Separator that is used for word splitting after expansion and to split lines into words with
the read builtin command. The default value is <space><tab><newline>.
echo $IFS
LANG Used to determine the locale category for any category not specifically selected with a variable starting with LC_. echo $LANG
PATH The search path for commands. It is a colon-separated list of directories in which the shell looks for commands. echo $PATH
PS1 Your prompt settings. echo $PS1
TMOUT The default timeout for the read builtin command. Also in an interactive shell, the value is interpreted as
the number of seconds to wait for input after issuing the command. If not input provided it will logout user.
echo $TMOUT
TERM Your login terminal type. echo $TERM
export TERM=vt100
SHELL Set path to login shell. echo $SHELL
DISPLAY Set X display name echo $DISPLAY
export DISPLAY=:0.1
EDITOR Set name of default text editor. export EDITOR=/usr/bin/vim

Examples :

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

1. A basic example of printing HOME variable value

$ printenv HOME
/home/abc

2. Display all variables

advertisement
$ printenv
SSH_AGENT_PID=2068
GPG_AGENT_INFO=/run/user/abc/keyring-LS1V1f/gpg:0:1
TERM=xterm
SHELL=/bin/bash
XDG_SESSION_COOKIE=f16900caaa04f54976c81f94527ce78c-1390028483.931288-1641264189
WINDOWID=50331653
GNOME_KEYRING_CONTROL=/run/user/abc/keyring-LS1V1f
GTK_MODULES=overlay-scrollbar
USER=abc
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:
XDG_SESSION_PATH=/org/freedesktop/DisplayManager/Session0
XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0
SSH_AUTH_SOCK=/run/user/abc/keyring-LS1V1f/ssh
SESSION_MANAGER=local/ubuntu:@/tmp/.ICE-unix/2023,unix/ubuntu:/tmp/.ICE-unix/2023
DEFAULTS_PATH=/usr/share/gconf/ubuntu.default.path
XDG_CONFIG_DIRS=/etc/xdg/xdg-ubuntu:/etc/xdg
PATH=/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
DESKTOP_SESSION=ubuntu
PWD=/home/abc
GNOME_KEYRING_PID=2012
LANG=en_US.UTF-8
MANDATORY_PATH=/usr/share/gconf/ubuntu.mandatory.path
UBUNTU_MENUPROXY=libappmenu.so
COMPIZ_CONFIG_PROFILE=ubuntu
GDMSESSION=ubuntu
SHLVL=1
HOME=/home/abc
GNOME_DESKTOP_SESSION_ID=this-is-deprecated
LOGNAME=abc
COMPIZ_BIN_PATH=/usr/bin/
XDG_DATA_DIRS=/usr/share/ubuntu:/usr/share/gnome:/usr/local/share/:/usr/share/
DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-2V9OQkg4x6,guid=90cc3c4b6217ee1c57912cd852da26c4
LESSOPEN=| /usr/bin/lesspipe %s
TEXTDOMAIN=im-config
XDG_RUNTIME_DIR=/run/user/abc
DISPLAY=:0
XDG_CURRENT_DESKTOP=Unity
LESSCLOSE=/usr/bin/lesspipe %s %s
TEXTDOMAINDIR=/usr/share/locale/
COLORTERM=gnome-terminal
XAUTHORITY=/home/abc/.Xauthority
_=/usr/bin/printenv

Sanfoundry Global Education & Learning Series – 1000 Linux Tutorials.

If you wish to look at all Linux commands and their usage examples, go to Linux Commands Tutorial.

advertisement

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.