grep options and fgrep


$grep -V
GNU grep 2.6.3

Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

$

GREP -F or fgrep

$grep -F H   hello.txt
Hello
$grep -F helloKello   hello.txt
$grep -F helloello   hello.txt
$grep -F hell   hello.txt
hello
helloo
hello
$time grep -F hell   hello.txt
hello
helloo
hello

real    0m0.009s
user    0m0.000s
sys     0m0.008s
$time grep  hell   hello.txt
hello
helloo
hello

real    0m0.009s
user    0m0.004s
sys     0m0.004s
$

grep -n ,-v , -c, -i

$grep -n root /etc/passwd
1:root:x:0:0:root:/root:/bin/bash
$

$cat hello.txt
hello
world
$grep -v hello hello.txt
world
$
$cat hello.txt
hello
world
helloo
$grep -c hello hello.txt
2
$grep -c helloo hello.txt
1
$
$cat hello.txt
hello
world
helloo
Hello

$grep  hello hello.txt
hello
helloo
$grep  -i hello hello.txt
hello
helloo
Hello
$

grep * wildcard

to match repetitions of a character a star is used.

$cat samsung
id proof
license copy
check leaf 1



$grep *p* samsung
$grep p* samsung
id proof
license copy
check leaf 1



$grep p samsung
id proof
license copy
$grep *p samsung
$grep * samsung
Binary file PCBSD8.0-x86-bootonly.iso matches
$grep "*"  samsung
$grep "p*"  samsung
id proof
license copy
check leaf 1



$grep "*p*"  samsung
$

terminfo is a database of terminal capabilities

$cd /lib/terminfo/
$ls
a  c  d  E  h  l  m  p  r  s  v  w  x
$pwd
/lib/terminfo
$cd l/
$infocmp linux
$infocmp linux
#       Reconstructed via infocmp from file: /lib/terminfo/l/linux
linux|linux console,
        am, bce, ccc, eo, mir, msgr, xenl, xon,
        colors#8, it#8, ncv#18, pairs#64,

Terminfo (formerly Termcap) is a database of terminal capabilities and more. For every (well almost) model of terminal it tells application programs what the terminal is capable of doing. It tells what escape sequences (or control characters) to send to the terminal in order to do things such as move the cursor to a new location, erase part of the screen, scroll the screen, change modes, change appearance (colors, brightness, blinking, underlining, reverse video etc.). After about 1980, many terminals supported over a hundred different commands (some of which take numeric parameters).

Copyright 1998-2010 by David S. Lawyer. dave@lafn.org

grepping through ncurses sources.
$grep terminfo  infocmp.c
 * terminfo entries, completely determine the actions of the program.
static ENTRY *entries;          /* terminfo entries */

$grep ENTRY dump_entry.h
#ifndef DUMP_ENTRY_H
#define DUMP_ENTRY_H 1
#endif /* DUMP_ENTRY_H */
$


duplicate selective acknowledgement

$cat /proc/sys/net/ipv4/tcp_dsack
1
$
tcp_dsack - BOOLEAN
Allows TCP to send "duplicate" SACKs.

This option is required to send duplicate SACKs which was briefly described in the tcp_sack variable explanation. This is described in detail within the RFC 2883. This RFC document explains in detail how to handle situations where a packet is received twice or out of order. D-SACK is an extension to standard SACK and is used to tell the sender when a packet was received twice (ie, it was duplicated). The D-SACK data can then be used by the transmitter to improve network settings and so on. This should be 100% backwards compatible with older implementations as long as the previous implementors have not tried to implement this into the old SACK option in their own fashion. This is extremely rare and should not be a problem for anyone.

Copyright © 2002 by Oskar Andreasson

http://www.icir.org/floyd/sacks.html

grepping through the linux kernel source 2.6.32
selected parts.
$grep -r tcp_dsack *
sysctl_net_ipv4.c:              .procname       = "tcp_dsack",
tcp_input.c:int sysctl_tcp_dsack __read_mostly = 1

Problem : find what is sysctl in the linux kernel code.

congestion control algorithm to be used for new connections

ahiliation:~$cat /proc/sys/net/ipv4/tcp_congestion_control
cubic
ahiliation:~$echo reno >  /proc/sys/net/ipv4/tcp_congestion_control
bash: /proc/sys/net/ipv4/tcp_congestion_control: Permission denied
ahiliation:~$su -
Password:
debianlabs:~# echo reno >  /proc/sys/net/ipv4/tcp_congestion_control
debianlabs:~# cat  /proc/sys/net/ipv4/tcp_congestion_control
reno
debianlabs:~# echo dreno >  /proc/sys/net/ipv4/tcp_congestion_control
-su: echo: write error: No such file or directory
Set the congestion control algorithm to be used for new
connections. The algorithm "reno" is always available, but
additional choices may be available based on kernel configuration.
Default is set as part of kernel configuration.
[ linux kernel source tcp_yeah.c ]
else if (!yeah->doing_reno_now) {
 /* Scalable */
tp->snd_cwnd_cnt += yeah->pkts_acked;
grepping through linux kernel source 2.6.32
sysctl_net_ipv4.c:              .procname       = "tcp_congestion_control",
sysctl_net_ipv4.c:              .proc_handler   = proc_tcp_congestion_control,
sysctl_net_ipv4.c:              .strategy       = sysctl_tcp_congestion_control,

Problem : Find exactly where the default algorithm is done in code