debug method development with “ls” command

$gdb /bin/ls
GNU gdb (Debian 7.11.1-2) 7.11.1
Copyright (C) 2016 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.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
.
Find the GDB manual and other documentation resources online at:
.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /bin/ls...Reading symbols from /usr/lib/debug/.build-id/d8/8582ece1631fd6d00210f2b98e1675dff8a222.debug...done.
done.
(gdb) break 1250
Breakpoint 1 at 0x39e7: file src/ls.c, line 1250.
(gdb) source src/ls.c
src/ls.c: No such file or directory.
(gdb) source ls.c
ls.c:1: Error in sourced command file:
Undefined command: "".  Try "help".
(gdb) r
Starting program: /bin/ls 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Breakpoint 1, main (argc=1, argv=0x7fffffffe228) at src/ls.c:1285
warning: Source file is more recent than executable.
1285	  set_program_name (argv[0]);
(gdb) next
1249	{
(gdb) next
1285	  set_program_name (argv[0]);
(gdb) l
1280	#if ! SA_NOCLDSTOP
1281	  bool caught_sig[nsigs];
1282	#endif
1283	
1284	  initialize_main (&argc, &argv);
1285	  set_program_name (argv[0]);
1286	  setlocale (LC_ALL, "");
1287	  bindtextdomain (PACKAGE, LOCALEDIR);
1288	  textdomain (PACKAGE);
1289	
(gdb) next
1286	  setlocale (LC_ALL, "");
(gdb) next
1287	  bindtextdomain (PACKAGE, LOCALEDIR);
(gdb) next
1288	  textdomain (PACKAGE);
(gdb) print PACKAGE
No symbol "PACKAGE" in current context.
(gdb) next
1291	  atexit (close_stdout);
(gdb) print PACKAGE
No symbol "PACKAGE" in current context.
(gdb) next
1290	  initialize_exit_failure (LS_FAILURE);
(gdb) next
1291	  atexit (close_stdout);
(gdb) next
1300	  current_time.tv_sec = TYPE_MINIMUM (time_t);
(gdb) c
Continuing.
[		  df.o		      id.c		 nproc		 seq.c			       tee.c
arch		  dir		      id.o		 nproc.c	 seq.o			       tee.o
base32		  dircolors	      install.c		 nproc.o	 set-fields.c		       test
base64		  dircolors.c	      ioblksize.h	 numfmt		 set-fields.h		       test.c
base64.c	  dircolors.h	      join		 numfmt.c	 set-fields.o		       test.o
basename	  dircolors.hin       join.c		 numfmt.o	 sha1sum		       timeout
basename.c	  dircolors.o	      join.o		 od		 sha224sum		       timeout.c
basename.o	  dirname	      kill		 od.c		 sha256sum		       timeout.o
cat		  dirname.c	      kill.c		 od.o		 sha384sum		       touch
cat.c		  dirname.o	      kill.o		 operand2sig.c	 sha512sum		       touch.c
cat.o		  du		      lbracket.c	 operand2sig.h	 shred			       touch.o
chcon		  du.c		      lbracket.o	 operand2sig.o	 shred.c		       tr
chcon.c		  du.o		      libstdbuf.c	 paste		 shred.o		       tr.c
chcon.o		  echo		      libstdbuf.so	 paste.c	 shuf			       tr.o
chgrp		  echo.c	      libver.a		 paste.o	 shuf.c			       true
chgrp.c		  echo.o	      link		 pathchk	 shuf.o			       true.c
chgrp.o		  env		      link.c		 pathchk.c	 single-binary.mk	       true.o
chmod		  env.c		      link.o		 pathchk.o	 sleep			       truncate
chmod.c		  env.o		      ln		 pinky		 sleep.c		       truncate.c
chmod.o		  expand	      ln.c		 pinky.c	 sleep.o		       truncate.o
chown		  expand.c	      ln.o		 pinky.o	 sort			       tsort
chown.c		  expand.o	      local.mk		 pr		 sort.c			       tsort.c
chown-core.c	  expr		      logname		 pr.c		 sort.o			       tsort.o
chown-core.h	  expr.c	      logname.c		 primes.h	 split			       tty
chown-core.o	  expr.o	      logname.o		 printenv	 split.c		       tty.c
chown.o		  extent-scan.c       longlong.h	 printenv.c	 split.o		       tty.o
chroot		  extent-scan.h       ls		 printenv.o	 src_base32-base64.o	       uname
chroot.c	  extent-scan.o       ls.c		 printf		 src_base64-base64.o	       uname-arch.c
chroot.o	  extract-magic       ls-dir.c		 printf.c	 src_ginstall-copy.o	       uname-arch.o
cksum		  factor	      ls-dir.o		 printf.o	 src_ginstall-cp-hash.o        uname.c
cksum.c		  factor.c	      ls.h		 pr.o		 src_ginstall-extent-scan.o    uname.h
cksum.o		  factor.o	      ls-ls.c		 prog-fprintf.c  src_ginstall-install.o        uname.o
comm		  false		      ls-ls.o		 prog-fprintf.h  src_ginstall-prog-fprintf.o   uname-uname.c
comm.c		  false.c	      ls.o		 prog-fprintf.o  src_ginstall-selinux.o        uname-uname.o
comm.o		  false.o	      ls-vdir.c		 ptx		 src_libstdbuf_so-libstdbuf.o  unexpand
copy.c		  fiemap.h	      ls-vdir.o		 ptx.c		 src_md5sum-md5sum.o	       unexpand.c
copy.h		  find-mount-point.c  make-prime-list	 ptx.o		 src_sha1sum-md5sum.o	       unexpand.o
copy.o		  find-mount-point.h  make-prime-list.c  pwd		 src_sha224sum-md5sum.o        uniq
coreutils-arch.c  find-mount-point.o  make-prime-list.o  pwd.c		 src_sha256sum-md5sum.o        uniq.c
coreutils.c	  fmt		      md5sum		 pwd.o		 src_sha384sum-md5sum.o        uniq.o
coreutils-dir.c   fmt.c		      md5sum.c		 readlink	 src_sha512sum-md5sum.o        unlink
coreutils.h	  fmt.o		      mkdir		 readlink.c	 stat			       unlink.c
coreutils-vdir.c  fold		      mkdir.c		 readlink.o	 stat.c			       unlink.o
cp		  fold.c	      mkdir.o		 realpath	 stat.o			       uptime
cp.c		  fold.o	      mkfifo		 realpath.c	 stdbuf			       uptime.c
cp-hash.c	  fs.h		      mkfifo.c		 realpath.o	 stdbuf.c		       uptime.o
cp-hash.h	  fs-is-local.h       mkfifo.o		 relpath.c	 stdbuf.o		       users
cp-hash.o	  getlimits	      mknod		 relpath.h	 stty			       users.c
cp.o		  getlimits.c	      mknod.c		 relpath.o	 stty.c			       users.o
csplit		  getlimits.o	      mknod.o		 remove.c	 stty.o			       vdir
csplit.c	  ginstall	      mktemp		 remove.h	 sum			       version.c
csplit.o	  group-list.c	      mktemp.c		 remove.o	 sum.c			       version.h
cu-progs.mk	  group-list.h	      mktemp.o		 rm		 sum.o			       version.o
cut		  group-list.o	      mv		 rm.c		 sync			       wc
cut.c		  groups	      mv.c		 rmdir		 sync.c			       wc.c
cut.o		  groups.c	      mv.o		 rmdir.c	 sync.o			       wc.o
date		  groups.o	      nice		 rmdir.o	 system.h		       who
date.c		  head		      nice.c		 rm.o		 tac			       whoami
date.o		  head.c	      nice.o		 runcon		 tac.c			       whoami.c
dcgen		  head.o	      nl		 runcon.c	 tac.o			       whoami.o
dd		  hostid	      nl.c		 runcon.o	 tac-pipe.c		       who.c
dd.c		  hostid.c	      nl.o		 selinux.c	 tail			       who.o
dd.o		  hostid.o	      nohup		 selinux.h	 tail.c			       yes
df		  hostname.c	      nohup.c		 selinux.o	 tail.o			       yes.c
df.c		  id		      nohup.o		 seq		 tee			       yes.o
[Inferior 1 (process 13843) exited normally]
(gdb) 

compressing and uncompressing a file with the help of xargs

$ls stderr.txt 
stderr.txt
$ls stderr.txt | xargs ls
stderr.txt
$ls stderr.txt | xargs cat
/home/jeffrin/quark/kernel/run_kernel.sh: line 10: ./main.native: No such file or directory
$ls stderr.txt | xargs gzip
$ls stderr.txt 
ls: cannot access 'stderr.txt': No such file or directory
$ls stderr.txt.gz | xargs gunzip 
$ls stderr.txt 
stderr.txt
$

Finding the number of processor units

ABOUT nproc

print the number of processing units available

TYPICAL COMMANDLINE SESSION
[bash]
$nproc
2
$nproc –ignore=1
1
$grep -c ^processor /proc/cpuinfo
2
$cat /proc/cpuinfo | awk ‘/^processor/{print $3=$3+1}’ | tail -1
2
$cat /proc/cpuinfo | awk ‘/^processor/{print $3}’
0
1
$lscpu | grep CPU
CPU op-mode(s): 32-bit, 64-bit
CPU(s): 2
On-line CPU(s) list: 0,1
CPU family: 21
CPU MHz: 2800.000
CPU max MHz: 3000.0000
CPU min MHz: 1400.0000
NUMA node0 CPU(s): 0,1
$lscpu | grep "CPU(s)"
CPU(s): 2
On-line CPU(s) list: 0,1
NUMA node0 CPU(s): 0,1
$lscpu | grep "CPU(s):"
CPU(s): 2
NUMA node0 CPU(s): 0,1
$lscpu | grep ^"CPU(s):"
CPU(s): 2
$lscpu | awk ‘FNR == 4 {print $2}’
2
$
[/bash]
LINKS
https://en.wikipedia.org/wiki/List_of_GNU_Core_Utilities_commands
http://man7.org/linux/man-pages/man1/nproc.1.html
https://blog.dbi-services.com/linux-how-to-monitor-the-nproc-limit-1/

finding the current state of a network cable

$sudo cat /sys/class/net/eth0/speed 
100
$sudo cat /sys/class/net/eth0/ca
carrier          carrier_changes  
$sudo cat /sys/class/net/eth0/carrier
1
$sudo cat /sys/class/net/eth0/carrier_changes 
2
$sudo cat /sys/class/net/eth0/operstate 
up
$sudo ethtool eth0
Settings for eth0:
	Supported ports: [ TP MII ]
	Supported link modes:   10baseT/Half 10baseT/Full 
	                        100baseT/Half 100baseT/Full 
	                        1000baseT/Half 1000baseT/Full 
	Supported pause frame use: No
	Supports auto-negotiation: Yes
	Advertised link modes:  10baseT/Half 10baseT/Full 
	                        100baseT/Half 100baseT/Full 
	                        1000baseT/Half 1000baseT/Full 
	Advertised pause frame use: Symmetric Receive-only
	Advertised auto-negotiation: Yes
	Link partner advertised link modes:  10baseT/Half 10baseT/Full 
	                                     100baseT/Half 100baseT/Full 
	Link partner advertised pause frame use: Symmetric Receive-only
	Link partner advertised auto-negotiation: Yes
	Speed: 100Mb/s
	Duplex: Full
	Port: MII
	PHYAD: 0
	Transceiver: internal
	Auto-negotiation: on
	Supports Wake-on: pumbg
	Wake-on: g
	Current message level: 0x00000033 (51)
			       drv probe ifdown ifup
	Link detected: yes
$

http://www.ostechnix.com/how-to-find-out-the-connected-
state-of-a-network-cable-in-linux/

httping with sending of username and password and flood ping

$httping -U www.beautifulwork.org
No URL/host to ping given

$httping -U http://www.beautifulwork.org
No URL/host to ping given

$httping  http://www.beautifulwork.org
PING www.beautifulwork.org:80 (/):
connected to 89.36.208.169:80 (224 bytes), seq=0 time=455.10 ms 
connected to 89.36.208.169:80 (224 bytes), seq=1 time=458.34 ms 
connected to 89.36.208.169:80 (224 bytes), seq=2 time=447.45 ms 
^CGot signal 2
--- http://www.beautifulwork.org/ ping statistics ---
4 connects, 3 ok, 0.00% failed, time 4418ms
round-trip min/avg/max = 447.5/453.6/458.3 ms
$httping -U anonymous http://www.beautifulwork.org
$httping -U anonymous http://www.beautifulwork.org
PING www.beautifulwork.org:80 (/):
connected to 89.36.208.169:80 (224 bytes), seq=0 time=453.33 ms 
connected to 89.36.208.169:80 (224 bytes), seq=1 time=459.89 ms 
connected to 89.36.208.169:80 (224 bytes), seq=2 time=451.59 ms 
connected to 89.36.208.169:80 (224 bytes), seq=3 time=455.54 ms 
connected to 89.36.208.169:80 (224 bytes), seq=4 time=448.82 ms 
^CGot signal 2
--- http://www.beautifulwork.org/ ping statistics ---
5 connects, 5 ok, 0.00% failed, time 6948ms
round-trip min/avg/max = 448.8/453.8/459.9 ms
$httping -U userfoo http://www.beautifulwork.org
PING www.beautifulwork.org:80 (/):
connected to 89.36.208.169:80 (224 bytes), seq=0 time=449.55 ms 
connected to 89.36.208.169:80 (224 bytes), seq=1 time=462.89 ms 
connected to 89.36.208.169:80 (224 bytes), seq=2 time=446.10 ms 
connected to 89.36.208.169:80 (224 bytes), seq=3 time=445.94 ms 
^CGot signal 2
--- http://www.beautifulwork.org/ ping statistics ---
4 connects, 4 ok, 0.00% failed, time 5721ms
round-trip min/avg/max = 445.9/451.1/462.9 ms
$httping -U userfoo -P withfoo http://www.beautifulwork.org
PING www.beautifulwork.org:80 (/):
connected to 89.36.208.169:80 (224 bytes), seq=0 time=459.03 ms 
connected to 89.36.208.169:80 (224 bytes), seq=1 time=445.85 ms 
connected to 89.36.208.169:80 (224 bytes), seq=2 time=489.32 ms 
connected to 89.36.208.169:80 (224 bytes), seq=3 time=461.37 ms 
^CGot signal 2
--- http://www.beautifulwork.org/ ping statistics ---
4 connects, 4 ok, 0.00% failed, time 5614ms
round-trip min/avg/max = 445.8/463.9/489.3 ms



$httping -f http://www.beautifulwork.org
PING www.beautifulwork.org:80 (/):
connected to 89.36.208.169:80 (224 bytes), seq=0 time=458.52 ms 
connected to 89.36.208.169:80 (224 bytes), seq=1 time=447.23 ms 
connected to 89.36.208.169:80 (224 bytes), seq=2 time=442.29 ms 
connected to 89.36.208.169:80 (224 bytes), seq=3 time=444.83 ms 
connected to 89.36.208.169:80 (224 bytes), seq=4 time=456.58 ms 
connected to 89.36.208.169:80 (224 bytes), seq=5 time=446.09 ms 
connected to 89.36.208.169:80 (224 bytes), seq=6 time=447.35 ms 
^CGot signal 2

--- http://www.beautifulwork.org/ ping statistics ---
8 connects, 7 ok, 12.50% failed, time 3580ms
round-trip min/avg/max = 442.3/449.0/458.5 ms
$

anonymous pages and memory from /proc/meminfo

$cat /proc/meminfo
MemTotal:        3495924 kB
MemFree:         1465276 kB
MemAvailable:    2353604 kB
Buffers:          126008 kB
Cached:           962924 kB
SwapCached:            0 kB
Active:          1330576 kB
Inactive:         452848 kB
Active(anon):     695532 kB
Inactive(anon):    29420 kB
Active(file):     635044 kB
Inactive(file):   423428 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:       7259132 kB
SwapFree:        7259132 kB
Dirty:               232 kB
Writeback:             0 kB

AnonPages: 694488 kB

Mapped: 291508 kB Shmem: 30464 kB Slab: 97912 kB SReclaimable: 65988 kB SUnreclaim: 31924 kB KernelStack: 7808 kB PageTables: 30060 kB NFS_Unstable: 0 kB Bounce: 0 kB WritebackTmp: 0 kB CommitLimit: 9007092 kB Committed_AS: 3508024 kB VmallocTotal: 34359738367 kB VmallocUsed: 0 kB VmallocChunk: 0 kB HardwareCorrupted: 0 kB AnonHugePages: 0 kB HugePages_Total: 0 HugePages_Free: 0 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kB DirectMap4k: 198692 kB DirectMap2M: 3432448 kB DirectMap1G: 0 kB $ https://blogs.oracle.com/cwb/entry/so_what_the_heck_is

sample session with “shopt -s cdspell” with Bash

$shopt -s 
checkwinsize   	on
cmdhist        	on
complete_fullquote	on
expand_aliases 	on
extglob        	on
extquote       	on
force_fignore  	on
histappend     	on
interactive_comments	on
progcomp       	on
promptvars     	on
sourcepath     	on
$shopt -s cdspell
$shopt -s 
cdspell        	on
checkwinsize   	on
cmdhist        	on
complete_fullquote	on
expand_aliases 	on
extglob        	on
extquote       	on
force_fignore  	on
histappend     	on
interactive_comments	on
progcomp       	on
promptvars     	on
sourcepath     	on
$shopt -s gnu
bash: shopt: gnu: invalid shell option name
$cd /etc/ap
apache2/    apm/        apparmor/   apparmor.d/ apport/     apt/        
$cd /etc/apache3
/etc/apache2
$pwd
/etc/apache2
$


http://www.gnu.org/software/bash/manual/html_node/The-Shopt-Builtin.html

appending file using “paste” command hack

$cat a.txt 
hello
$cat b.txt 
killo
$ls
1  a.txt  b.txt  l.txt  trueangle  u.txt
$cat u.txt 
UPPERCASE
$cat l.txt 
uppercase
$cat a.txt >> b.txt >> l.txt >> u.txt 
$cat u.txt 
UPPERCASE
hello
$cat a.txt 
hello
$cat 
1          a.txt      b.txt      l.txt      trueangle/ u.txt      
$cat l.txt 
uppercase
$cat a.txt 
hello
$cat a.txt >> b.txt 
$cat b.txt 
killo
hello
$cat l.txt >> u.txt 
$cat u.txt 
UPPERCASE
hello
uppercase
$paste b.txt u.txt > final.txt
$cat final.txt 
killo	UPPERCASE
hello	hello
	uppercase
$sort -t: -k1 final.txt 
hello	hello
killo	UPPERCASE
	uppercase
$