GREP_COLORS – change the colors in the GREP output.

2019-04-22 4 min read Bash Linux

Today we will look at the variable GREP_COLORS. This variable determines the colour that is used with the grep command. You can look at the man page of the grep command to see what the various options mean. Here is the excerpt from the man command:

GREP_COLORS
          Specifies the colors and other attributes used to highlight various  parts  of  the
          output.   Its  value  is  a  colon-separated  list of capabilities that defaults to
          ms=01;31:mc=01;31:sl=:cx=:fn=35:ln=32:bn=32:se=36  with  the  rv  and  ne   boolean
          capabilities omitted (i.e., false).  Supported capabilities are as follows.

          sl=    SGR  <a class="zem_slink" title="Substring" href="http://en.wikipedia.org/wiki/Substring" rel="wikipedia">substring</a>  for  whole  selected lines (i.e., matching lines when the -v
                 command-line option is omitted, or non-matching lines when -v is specified).
                 If however the boolean rv capability and the -v command-line option are both
                 specified, it applies to context matching lines  instead.   The  <a class="zem_slink" title="Default (finance)" href="http://en.wikipedia.org/wiki/Default_%28finance%29" rel="wikipedia">default</a>  is
                 empty (i.e., the terminal's default color pair).

          cx=    SGR  substring for whole context lines (i.e., non-matching lines when the -v
                 command-line option is omitted, or matching lines when -v is specified).  If
                 however  the  boolean  rv capability and the -v command-line option are both
                 specified, it applies to selected non-matching lines instead.   The  default
                 is empty (i.e., the terminal's default color pair).

          rv     <a class="zem_slink" title="Boolean data type" href="http://en.wikipedia.org/wiki/Boolean_data_type" rel="wikipedia">Boolean  value</a>  that  reverses  (swaps)  the  meanings  of  the  sl= and cx=
                 capabilities when the -v command-line option is specified.  The  default  is
                 false (i.e., the capability is omitted).

          mt=01;31
                 SGR  substring  for  matching  <a class="zem_slink" title="Empty set" href="http://en.wikipedia.org/wiki/Empty_set" rel="wikipedia">non-empty</a>  text in any matching line (i.e., a
                 selected line when the -v command-line option is omitted, or a context  line
                 when  -v  is specified).  Setting this is equivalent to setting both ms= and
                 mc= at once to the same value.  The default is a bold  red  text  foreground
                 over the current line background.

          ms=01;31
                 SGR substring for matching non-empty text in a selected line.  (This is only
                 used when the -v command-line option is omitted.)  The effect of the sl= (or
                 cx=  if  rv) capability remains active when this kicks in.  The default is a
                 bold red text foreground over the current line background.

          mc=01;31
                 SGR substring for matching non-empty text in a context line.  (This is  only
                 used  when  the -v command-line option is specified.)  The effect of the cx=
                 (or sl= if rv) capability remains active when this kicks in.  The default is
                 a bold red text foreground over the current line background.

          fn=35  SGR  substring  for file names prefixing any content line.  The default is a
                 magenta text foreground over the terminal's default background.

          ln=32  SGR substring for <a class="zem_slink" title="Line number" href="http://en.wikipedia.org/wiki/Line_number" rel="wikipedia">line numbers</a> prefixing any content line.  The default is a
                 green text foreground over the terminal's default background.

          bn=32  SGR substring for byte offsets prefixing any content line.  The default is a
                 green text foreground over the terminal's default background.

          se=36  SGR substring for separators that are inserted between selected line  fields
                 (:),  between context line fields, (-), and between groups of adjacent lines
                 when nonzero context  is  specified  (--).   The  default  is  a  cyan  text
                 foreground over the terminal's default background.

          ne     Boolean  value that prevents clearing to the <a class="zem_slink" title="Newline" href="http://en.wikipedia.org/wiki/Newline" rel="wikipedia">end of line</a> using Erase in Line
                 (EL) to Right (\33[K) each time a colorized item ends.  This  is  needed  on
                 terminals on which EL is not supported.  It is otherwise useful on terminals
                 for which the back_color_erase (bce) boolean terminfo  capability  does  not
                 apply,  when  the  chosen  highlight colors do not affect the background, or
                 when EL is too slow or causes too much flicker.  The default is false (i.e.,
                 the capability is omitted).

Continue reading

findmnt – find all the mounts and their source

2013-09-16 1 min read Linux

If you are looking for the source of a mount and the various options used in the mount, then the quickest way to get that is ::

findmnt

By default, with no parameters, it lists all the mounts in a tree like view and all the options used to mount the path. It also lists the source of the mount.

By default again, it uses some capabilities of the terminal to show the tree which you can disable with the option “-a”.

Continue reading

Print all environment variables, including hidden ones

2010-11-09 2 min read Bash Fedora Linux

Print all environment variables, including hidden ones

  <td>
    <div class="text codecolorer">
      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
    </div>
  </td>
</tr>
1

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.

Continue reading

cdargs – bash cd command with bookmarks and browser.

2010-06-22 0 min read Bash Learning Linux
\"Screenshot
Image via Wikipedia

cdargs is a <a class="zem_slink freebase/en/bash" title="Bash" rel="homepage" href="http://tiswww.case.edu/php/chet/bash/bashtop.html">bash shell cd with bookmarks and browser. Quite useful if you are developer or someone who use&#8217;s the bash shell very frequently

Name       : cdargs

Arch : i686 Version : 1.35 Release : 5.fc12 Size : 114 k Repo : installed From repo : fedora Summary : The shell cd with bookmarks and browser URL : http://www.skamphausen.de/software/cdargs/ License : <a class="zem_slink freebase/en/gnu_general_public_license" title="GNU General Public License" rel="wikipedia" href="http://en.wikipedia.org/wiki/GNU_General_Public_License">GPLv2</a>+ Description: Enables the user to quickly change <a class="zem_slink freebase/en/working_directory" title="Working directory" rel="wikipedia" href="http://en.wikipedia.org/wiki/Working_directory">working directory</a> by navigating cd arguments : and expanding the shell built-in cd with bookmarks and browser.

Continue reading

The power of find command in Linux – advanced.

2010-05-24 2 min read Linux

Generally whoever uses Linux, would know about the find command. Find the man page <a href="http://amit.themafia.info/phpMan.php?parameter=find&mode=man" target="_blank">here.

There are also lots of blogs, tutorials and other articles on find command on the web, so why write another one. Because it&#8217;s worth every word spent on it 🙂
find is a very powerful command, let&#8217;s see how (options for find command from man page and usage):

depth — Process each directory&#8217;s contents before the directory itself.
maxdepth — Descend at most <span style="text-decoration: underline;">levels (a non-negative integer) levels of directories below the command line arguments.
xdev — Don&#8217;t descend directories on other filesystems.
executable — Matches files which are executable and directories which are searchable (in a file name resolution sense).
This takes into account access control lists and other permissions artefacts which the -perm test ignores.
iname — Like -name, but the match is case insensitive.
nogroup — No group corresponds to file&#8217;s numeric group ID.
nouser — No user corresponds to file&#8217;s numeric user ID.
fls <span style="text-decoration: underline;">file — True; like -ls but write to <span style="text-decoration: underline;">file like -fprint.
ok <span style="text-decoration: underline;">command — Like -exec but ask the user first (on the standard input);
print0 — True; print the full file name on the standard output, followed by a null character
(instead of the newline character that -print uses).
printf <span style="text-decoration: underline;">format — True; print <span style="text-decoration: underline;">format on the standard output, interpreting &#8217;&#8217; escapes and &#8217;%&#8217; directives.

Continue reading

coproc help - a new feature in bash

2010-05-10 0 min read Bash Fedora Linux
\"Screenshot
Image via Wikipedia

In the <a class="zem_slink freebase/en/bash" title="Bash" rel="homepage" href="http://tiswww.case.edu/php/chet/bash/bashtop.html">bash version 4.0, there is a new concept called coproc. This is very useful for some of the daily tasks.

co-<a class="zem_slink freebase/guid/9202a8c04000641f800000000005a409" title="Process (computing)" rel="wikipedia" href="http://en.wikipedia.org/wiki/Process_%28computing%29">process starts a process in the background, optionally with a NAME, with which other processes can communicate. This can be a very <a class="zem_slink freebase/en/substitute_good" title="Substitute good" rel="wikipedia" href="http://en.wikipedia.org/wiki/Substitute_good">good substitution for <a class="zem_slink freebase/guid/9202a8c04000641f800000000048fac5" title="Pipeline (Unix)" rel="wikipedia" href="http://en.wikipedia.org/wiki/Pipeline_%28Unix%29">pipes in lots of cases. You can learn more about coproc in the link below:

Continue reading

top - looks better and is more useful with a rc file...

2010-05-07 1 min read Fedora Learning Linux

top is a very useful command to find out who is eating up the <a class="zem_slink freebase/en/central_processing_unit" title="Central processing unit" rel="wikipedia" href="http://en.wikipedia.org/wiki/Central_processing_unit">CPU or the memory. But sometimes the plain and simple look simply would be boring so how about some fun. Copy the below code to file : ~/.toprc

RCfile for &#8221;top&#8221;
Id:a, Mode_altscr=1, Mode_irixps=0, Delay_time=5.000, Curwin=0
Def    fieldscur=mfcAbdEgHIursOpQTvyzWjKNLX
winflags=32184, sortindx=10, maxtasks=0
summclr=4, msgsclr=5, headclr=5, taskclr=4
Job    fieldscur=ABcefgjlrstuvyzMKNHIWOPQDX
winflags=62777, sortindx=0, maxtasks=0
summclr=6, msgsclr=6, headclr=7, taskclr=6
Mem    fieldscur=ANOPQRSTUVbcdefgjlmyzWHIKX
winflags=62777, sortindx=13, maxtasks=0
summclr=5, msgsclr=5, headclr=4, taskclr=5
Usr    fieldscur=ABDECGfhijlopqrstuvyzMKNWX
winflags=62777, sortindx=4, maxtasks=0
summclr=3, msgsclr=3, headclr=2, taskclr=3

Continue reading