getopt . more on parse command options

commandline session

$getopt hello
 --
$getopt helloo
 --
$getopt hellooo
 --
$getopt hellooo how
 -- how
$getopt hellooo how are
 -- how are
$getopt h how are
 -- how are
$getopt h h h
 -- h h
$getopt ab -a
 -a --
$getopt ab -ab
 -a -b --
$getopt ab -ab -R
getopt: invalid option -- 'R'
 -a -b --
$getopt ab -ab -l
getopt: invalid option -- 'l'
 -a -b --
$getopt ab -abl
getopt: invalid option -- 'l'
 -a -b --
$getopt ab -abn
getopt: invalid option -- 'n'
 -a -b --
$getopt ab -abc
getopt: invalid option -- 'c'
 -a -b --
$getopt nl -nl
 -n -l --
$getopt R -nl
getopt: invalid option -- 'n'
getopt: invalid option -- 'l'
 --
$getopt R -R
 -R --
$

vmstat . more on virtual memory statistics

commandline session

$vmstat -s
      1995396 K total memory
      1197836 K used memory
       599976 K active memory
       483048 K inactive memory
       797560 K free memory
        49620 K buffer memory
       648028 K swap cache
      5843964 K total swap
            0 K used swap
      5843964 K free swap
       261891 non-nice user cpu ticks
          534 nice user cpu ticks
        68515 system cpu ticks
      1118198 idle cpu ticks
        17369 IO-wait cpu ticks
            0 IRQ cpu ticks
         2940 softirq cpu ticks
            0 stolen cpu ticks
       629227 pages paged in
       700676 pages paged out
            0 pages swapped in
            0 pages swapped out
      5625600 interrupts
     14181960 CPU context switches
   1372693030 boot time
         5917 forks
$

http://superuser.com/questions/101183/what-is-a-cpu-tick

stat . more from stat command

commandline session

$ls
store  store1
$pwd
/home/jeffrin/Test
$stat store
  File: ‘store’
  Size: 19        	Blocks: 8          IO Block: 4096   regular file
Device: 801h/2049d	Inode: 7036935     Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/ jeffrin)   Gid: ( 1000/ jeffrin)
Access: 2013-06-29 18:37:33.000000000 +0530
Modify: 2013-06-29 18:37:30.000000000 +0530
Change: 2013-06-29 18:37:30.000000000 +0530
 Birth: -
$stat -f store
  File: "store"
    ID: f7da53a314c76a3d Namelen: 255     Type: ext2/ext3
Block size: 4096       Fundamental block size: 4096
Blocks: Total: 581002890   Free: 23134751   Available: 20155347
Inodes: Total: 14901248   Free: 134100922
$stat -t store
store 19 8 81a4 1000 1000 801 7036935 1 0 0 1372511253 1372511250 1372511250 0 4096
$stat -f -t store
store f7da53a314c76a3d 255 ef53 4096 4096 581002890 23134516 20155112 14901248 134100919
$stat -f -t -c %A store
?
$stat  -c %A store
-rw-r--r--
$stat  -c %m store
/
$stat  -c %G store
jeffrin
$stat  -c %i store
7036935
$stat  -c %n store
store
$

nc netcat

commandline session

$nc 127.0.0.1 25
220 debian.Jeff ESMTP Exim 4.80 Thu, 27 Jun 2013 00:05:20 +0530
^C
$nc gnu.org
no port[s] to connect to
$nc gnu.org 25
^C
$nc -g gnu.org 25
no port[s] to connect to
$nc -g gnu.org gnu.org 25
^C
$nc -g 127.0.0.1 127.0.0.1  25
^C
$nc www.youtube.com
no port[s] to connect to
$nc www.youtube.com 80
^C
$
$nc -z -vv www.gnu.org  80
wildebeest.gnu.org [208.118.235.148] 80 (http) open
 sent 0, rcvd 0
$nc -z -vv 127.0.0.1  80
localhost.localdomain [127.0.0.1] 80 (http) : Connection refused
 sent 0, rcvd 0
$nc -z -vv 127.0.0.1  25
localhost.localdomain [127.0.0.1] 25 (smtp) open
 sent 0, rcvd 0
$

pstree display a tree of processes

commandline session

$pstree -A jeffrin
at-spi2-registr---{at-spi2-registr}

dbus-daemon

dbus-daemon

dbus-launch

dbus-launch

dconf-service---2*[{dconf-service}]

gconfd-2

gnome-session-+-at-spi-bus-laun-+-dbus-daemon
              |                 `-3*[{at-spi-bus-laun}]
              |-bluetooth-apple---{bluetooth-apple}
              |-gdu-notificatio
              |-gnome-fallback----2*[{gnome-fallback-}]
              |-gnome-panel-+-chrome-+-chrome
              |             |        |-chrome-sandbox---chrome-+-chrome-+-chrome---11*[{c+
              |             |        |                         |        `-3*[chrome---3*[+
              |             |        |                         `-nacl_helper_boo
              |             |        `-31*[{chrome}]
              |             |-gnome-terminal-+-bash---pstree
              |             |                |-bash
              |             |                |-gnome-pty-helpe
              |             |                `-3*[{gnome-terminal}]
              |             `-3*[{gnome-panel}]
              |-gnome-screensav---2*[{gnome-screensav}]
              |-gnome-settings--+-sh
              |                 `-3*[{gnome-settings-}]
              |-gnome-sound-app---{gnome-sound-app}
              |-metacity---3*[{metacity}]
              |-nm-applet---3*[{nm-applet}]
              |-notification-da---{notification-da}
              |-polkit-gnome-au---{polkit-gnome-au}
              |-ssh-agent
              |-tracker-miner-f---3*[{tracker-miner-f}]
              |-tracker-store---6*[{tracker-store}]
              `-3*[{gnome-session}]

gnome-keyring-d---6*[{gnome-keyring-d}]

goa-daemon---{goa-daemon}

gsd-printer---{gsd-printer}

gvfs-afc-volume---{gvfs-afc-volume}

gvfs-gdu-volume

gvfs-gphoto2-vo

gvfsd

gvfsd-metadata

mission-control---2*[{mission-control}]

pulseaudio---2*[{pulseaudio}]
$

true and false notes

A UNIX Command

$true
$echo $?
0
$false
$echo $?
1
$

$ ./true --version >&-
./true: write error: Bad file number
$ ./true --version > /dev/full
./true: write error: No space left on device


UNIX Explanation

true - do nothing, successfully
exit with a status code indicating success.
false - do nothing, unsuccessfully
exit with a status code indicating failure.

Related Source Code Exposition

int
main (int argc, char **argv)
{

  if (argc == 2)
    {
      initialize_main (&argc, &argv);
      set_program_name (argv[0]);
      setlocale (LC_ALL, "");
      bindtextdomain (PACKAGE, LOCALEDIR);
      textdomain (PACKAGE);

      atexit (close_stdout);

      if (STREQ (argv[1], "--help"))
        usage (EXIT_STATUS);

      if (STREQ (argv[1], "--version"))
        version_etc (stdout, PROGRAM_NAME, PACKAGE_NAME, Version, AUTHORS,
                     (char *) NULL);
    }

  exit (EXIT_STATUS);
}
 

Source Code Highlight

Recognize --help or --version only if it's the only
command-line argument.

Featured Image

Related Knowledge

`true' does  nothing except return  an exit status  of 0,
meaning "success".  It  can be used as a  place holder in
shell  scripts  where  a  successful command  is  needed,
although the  shell built-in  command `:' (colon)  may do
the same thing faster.   In most modern shells, `true' is
a built-in command,  so when you use `true'  in a script,
you're probably  using the built-in command,  not the one
documented here.

Note,  however, that it  is possible  to cause  `true' to
exit   with  nonzero   status:  with   the   `--help'  or
`--version'  option,  and  with standard  output  already
closed or redirected to a  file that evokes an I/O error.
For example, using a Bourne-compatible shell:

This version of `true' is implemented as a C program, and
is  thus  more secure  and  faster  than  a shell  script
implementation, and  may safely be used as  a dummy shell
for the purpose of disabling accounts.

source : info coreutils ‘true invocation’