Commands tagged environment (13)

  • Print environment (system) information using Perl.

    perl -e 'print map { $_ .= "$ENV{$_}\n" } (keys %ENV)'
    MarxBro · 2012-10-13 23:38:28 0
  • This uses some tricks I found while reading the bash man page to enumerate and display all the current environment variables, including those not listed by the 'env' command which according to the bash docs are more for internal use by BASH. The main trick is the way bash will list all environment variable names when performing expansion on ${!A*}. Then the eval builtin makes it work in a loop. I created a function for this and use it instead of env. (by aliasing env). This is the function that given any parameters lists the variables that start with it. So 'aae B' would list all env variables starting wit B. And 'aae {A..Z} {a..z}' would list all variables starting with any letter of the alphabet. And 'aae TERM' would list all variables starting with TERM. aae(){ local __a __i __z;for __a in "$@";do __z=\${!${__a}*};for __i in `eval echo "${__z}"`;do echo -e "$__i: ${!__i}";done;done; } And my printenv replacement is: alias env='aae {A..Z} {a..z} "_"|sort|cat -v 2>&1 | sed "s/\\^\\[/\\\\033/g"' From: Show Sample Output

    for _a in {A..Z} {a..z};do _z=\${!${_a}*};for _i in `eval echo "${_z}"`;do echo -e "$_i: ${!_i}";done;done|cat -Tsv
    AskApache · 2010-10-27 07:16:54 0
  • Grabs the cmdline used to execute the process, and the environment that the process is being run under. This is much different than the 'env' command, which only lists the environment for the shell. This is very useful (to me at least) to debug various processes on my server. For example, this lets me see the environment that my apache, mysqld, bind, and other server processes have. Here's a function I use: aa_ps_all () { ( cd /proc && command ps -A -opid= | xargs -I'{}' sh -c 'test $PPID -ne {}&&test -r {}/cmdline&&echo -e "\n[{}]"&&tr -s "\000" " "<{}/cmdline&&echo&&tr -s "\000\033" "\nE"<{}/environ|sort&&cat {}/limits' ); } From my .bash_profile at Show Sample Output

    cd /proc&&ps a -opid=|xargs -I+ sh -c '[[ $PPID -ne + ]]&&echo -e "\n[+]"&&tr -s "\000" " "<+/cmdline&&echo&&tr -s "\000\033" "\nE"<+/environ|sort'
    AskApache · 2010-10-22 02:34:33 4
  • Same as previous but compatible with BSD/IPSO

    ps ewwo command PID | tr ' ' '\n' | grep \=
    egreSS · 2011-09-15 12:07:46 0
  • Normally the bash builtin command 'set' displays all vars and functions. This just shows the vars. Useful if you want to see different output then env or declare or export. Alias 'sete' shows sets variables alias sete='set|sed -n "/^`declare -F|sed -n "s/^declare -f \(.*\)/\1 ()/p;q"`/q;p"' Alias setf shows the functions. alias setf='set|sed -n "/^`declare -F|sed -n "s/^declare -f \(.*\)/\1 ()/p;q"`/,\$p"' Also see: At the very least, some cool sed commands! From my .bash_profile Show Sample Output

    alias sete='set|sed -n "/^`declare -F|sed -n "s/^declare -f \(.*\)/\1 ()/p;q"`/q;p"'
    AskApache · 2010-11-17 23:58:01 5
  • Python virtual environment creation.

    $sudo aptitude install python-virtualenv; virtualenv --no-site-packages jpaenv; source jpaenv/bin/activate
    moulip · 2011-04-21 08:28:18 0
  • This exports all lines of input file as environment variables, assuming each line is like these: OH=YEAH FU=UUUU

    while read line; do export $line; done < <(cat input)
    dario · 2013-03-15 08:14:04 0
  • Sometimes there are just no variables such as $DESKTOP_SESSION, $GDMSESSION, or $WINDOWMANAGER. Show Sample Output

    ls -l /usr/share/xsessions/
    puresky · 2014-01-17 05:09:18 0
  • Normally executing 'set' returns a vast amount of information, including the source code of every function and variable within the environment - including those that are part of the shell. By using the -o posix argument, bash runs temporarily in POSIX mode for this command, which simplifies expressions and leaves out the shell's own functions and definitions - leaving a much smaller, more useful list. Show Sample Output

    alias allvars=' ( set -o posix; set ) | less'
    incidentnormal · 2016-03-04 14:04:45 0

  • 0
    eval "unset $(printenv | grep -ioP '(?:https?|no)_proxy' | tr '\n' ' ')"
    acavagni · 2019-06-28 10:40:41 1
  • This function is used to set environmental variables from a list of alternatives depending on what's installed on the system. It returns the first program found in the list. Example usage: export BROWSER=$(find_alternatives chromium-browser google-chrome opera firefox firefox-bin iceweasel konqueror w3m lynx) . export EDITOR=$(find_alternatives vim nano pico emacs kate) . export PAGER=$(find_alternatives vimpager less most more pg)

    find_alternatives(){ for i;do which "$i" >/dev/null && { echo "$i"; return 0;};done;return 1;}
    eightmillion · 2011-01-06 19:53:46 0

  • -1
    tatwright · 2012-10-14 17:47:18 0

  • -1
    perl -e 'print "$_=$ENV{$_}\n" for keys %ENV'
    sgikas · 2012-11-12 13:14:28 0

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Check These Out

Get all these commands in a text file with description.
I tried out on my Mac, jot to generate sequence ( 0,25,50,..), you can use 'seq' if it is linux to generate numbers, need curl installed on the machine, then it rocks. @Satya

tail: watch a filelog
-f file(s) to be monitorized -n number of last line to be printed on the screen in this example, the content of two files are displayed

Paste the contents of OS X clipboard into a new text file

nagios wrapper for any script/cron etc
use w/ check_freshness. passes the last line of output and exit code to nagios via nsca

Show number of NIC's, ports per nic and PCI address

Generate an XKCD #936 style 4 word password
The improvement of this command over Strawp's original alternative is that you can specify the size of the words, in this particular case words between 3 and 5 character's long. It also excludes words that contain apostrophes, if you'd rather keep those words simply substitue [^'] for .

open path with your default program (on Linux/*BSD)
open [path] in the default program, regardless of which Desktop Environment you use (KDE, GNOME, etc.) Works on all "" compatible desktop environments

Which processes are listening on a specific port (e.g. port 80)
swap out "80" for your port of interest. Can use port number or named ports e.g. "http"

Who needs pipes?
or: C

Copy a file to a new directory created on the fly
You need to cp, mv, scp, ..., some files around from one place to another, and after having laboriously typed out the source path, you remember that the destination directory doesn't yet exist, and so the command will fail. So rather than killing the command line and starting over, just interpolate the results of creating the directory and echo its name. You could DRY this with a for; do; done, but that may be more trouble than it's worth.

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: