$p Display all 428 possibilities? (y or n) $p bash: p: command not found $cat .inputrc set show-all-if-ambiguous on $ related text: Specifies the duration Readline will wait for a character when reading an ambiguous key sequence (one that can form a complete key sequence using the input read so far, or can take additional input to complete a longer key sequence).
enclose one or more commands inside a pair of parentheses
$ls
1
$( ls date )
ls: cannot access date: No such file or directory
$( `ls` date )
bash: 1: command not found
$cat 1
B$
$( ls `date` )
ls: cannot access Mon: No such file or directory
ls: cannot access Feb: No such file or directory
ls: cannot access 22: No such file or directory
ls: cannot access 21:36:34: No such file or directory
ls: cannot access IST: No such file or directory
ls: cannot access 2016: No such file or directory
$( `ls` `date` )
bash: 1: command not found
$( ls time )
ls: cannot access time: No such file or directory
$( ls `time` )
real 0m0.000s
user 0m0.000s
sys 0m0.000s
1
$( ls pwd )
ls: cannot access pwd: No such file or directory
$ls pwd
ls: cannot access pwd: No such file or directory
$( ls ) ( pwd )
bash: syntax error near unexpected token `('
$ls date
ls: cannot access date: No such file or directory
$`ls` date
bash: 1: command not found
$ls `date`
ls: cannot access Mon: No such file or directory
ls: cannot access Feb: No such file or directory
ls: cannot access 22: No such file or directory
ls: cannot access 21:41:17: No such file or directory
ls: cannot access IST: No such file or directory
ls: cannot access 2016: No such file or directory
$ (ls pwd )
ls: cannot access pwd: No such file or directory
$x =1
bash: x: command not found
$x = 1
bash: x: command not found
$$x = 1
bash: =: command not found
$ (x = 1)
bash: x: command not found
$x=1
$echo $x
1
$(echo $x)
1
$echo $x
1
$(x=2;echo $x)
2
$echo $x
1
$(x=2 echo $x)
1
$echo $x
1
$(x=2;echo $x)
2
$
http://www.tldp.org/LDP/abs/html/subshells.html
http://unix.stackexchange.com/questions/138463/do-parentheses-really-put-the-command-in-a-subshell
sample interaction with bash shell from the GNU project
$echo $BASH /bin/bash $echo $BASH_ $echo $BASH_v $echo $BASH_VERSION 4.3.42(1)-release $date || time Sun Feb 21 23:15:50 IST 2016 $datei || time bash: datei: command not found real 0m0.000s user 0m0.000s sys 0m0.000s $dateno || time bash: dateno: command not found real 0m0.000s user 0m0.000s sys 0m0.000s $time || date bash: syntax error near unexpected token `||' $time || date bash: syntax error near unexpected token `||' $time real 0m0.000s user 0m0.000s sys 0m0.000s $time || date bash: syntax error near unexpected token `||' $`time` || date real 0m0.000s user 0m0.000s sys 0m0.000s $time && date bash: syntax error near unexpected token `&&' $`time` && date real 0m0.000s user 0m0.000s sys 0m0.000s Sun Feb 21 23:25:24 IST 2016 $`timei` && date bash: timei: command not found $date && time Sun Feb 21 23:25:55 IST 2016 real 0m0.000s user 0m0.000s sys 0m0.000s $ http://askubuntu.com/questions/372926/bash-syntax-error-near-unexpected-token
the need of a command named “builtin”
$builtin echo jeffrin
jeffrin
$echo jeffrin
jeffrin
$echo() { echo "hi"; };
$echo jeffrin
^C
$builtin echo jeffrin
jeffrin
$echo jeffrin
^C
$
https://en.wikipedia.org/wiki/Shell_builtin
http://unix.stackexchange.com/questions/11454/what-is-the-
difference-between-a-builtin-command-and-one-that-is-not
(jeffrin) what is the use of the command named "builtin"
(jeffrin) llua : hello
(llua) to avoid a possible wrapper
a session with tsort command involving topological sorting
$tsort 1 tsort: -: input contains an odd number of tokens $tsort 1 2 1 2 $tsort 0 1 2 3 4 5 0 2 4 1 3 5 $tsort 0 1 2 3 4 5 0 2 4 1 3 5 $ http://www.geeksforgeeks.org/topological-sorting/ https://www.quora.com/What-are-some-real-world-applications-of-topological-sort
A typical hack with strace command which traces a ping command
ABOUT strace
strace is a diagnostic, debugging and instructional userspace utility for Linux. It is used to monitor and tamper with interactions between processes and the Linux kernel, which include system calls, signal deliveries, and changes of process state. The operation of strace is made possible by the kernel feature known as ptrace.
TYPICAL strace COMMAND RELATED
[bash]
$sudo strace -c -p `pidof ping`
strace: Process 4792 attached
% time seconds usecs/call calls errors syscall
—— ———– ———– ——— ——— —————-
43.34 0.001631 203 8 sendto
24.79 0.000933 116 8 1 recvmsg
16.40 0.000617 56 11 write
13.13 0.000494 70 7 poll
1.44 0.000054 54 1 restart_syscall
0.90 0.000034 34 1 1 rt_sigreturn
—— ———– ———– ——— ——— —————-
100.00 0.003763 36 2 total
$
[/bash]
LINK
https://en.wikipedia.org/wiki/Strace
https://www.tecmint.com/strace-commands-for-troubleshooting-and-debugging-linux/
sample session involving “env” and “unset” commands
ABOUT env
env is a shell command for Unix and Unix-like operating systems. It is used to either print a list of environment variables or run another utility in an altered environment without having to modify the currently existing environment. Using env, variables may be added or removed, and existing variables may be changed by assigning new values to them. In practice, env has another common use. It is often used by shell scripts to launch the correct interpreter. In this usage, the environment is typically not changed.
ABOUT unset
unset is a builtin command implemented by both the Bourne shell family (sh, ksh, bash, etc.) and the C shell family (csh, tcsh, etc.) of Unix command line shells. It unsets a shell variable, removing it from memory and the shell's exported environment. It is implemented as a shell builtin, because it directly manipulates the internals of the shell.[2][3] Read-only shell variables cannot be unset. If one tries to unset a read-only variable, the unset command will print an error message and return a non-zero exit code.
A TYPICAL SHELL SESSION
[bash]
$ls -l
total 0
-rw-r–r– 1 jeffrin jeffrin 0 Jan 27 00:13 hello
-rw-r–r– 1 jeffrin jeffrin 0 Jan 27 00:14 world
$pwd
/home/jeffrin/sample
$env -i HOME=/home/jeffrin `cd`
HOME=/home/jeffrin
$pwd
/home/jeffrin/sample
$ls
hello world
$env -i bash
jeffrin@debian:/home/jeffrin/sample$ echo $TERM
dumb
jeffrin@debian:/home/jeffrin/sample$ echo $PS1
${debian_chroot:+($debian_chroot)}\u@\h:\w\$
jeffrin@debian:/home/jeffrin/sample$ export PS1=>
bash: syntax error near unexpected token `newline’
jeffrin@debian:/home/jeffrin/sample$ export PS1=">"
>unset $PS1
bash: unset: `>’: not a valid identifier
>unset PS1
export PS1=$
$
[/bash]
LINKS
https://en.wikipedia.org/wiki/Env
https://en.wikipedia.org/wiki/Environment_variable#unset_command
how to backup and restore file permissions using acl
$mkdir data $cd data/ $ls $pwd /home/jeffrin/data $echo hello > file1.txt $echo world > file2.txt $ls -l total 8 -rw-r--r-- 1 jeffrin jeffrin 6 Jan 22 22:44 file1.txt -rw-r--r-- 1 jeffrin jeffrin 6 Jan 22 22:44 file2.txt $getfacl -R . > permissions.txt $cat permissions.txt # file: . # owner: jeffrin # group: jeffrin user::rwx group::r-x other::r-x # file: permissions.txt # owner: jeffrin # group: jeffrin user::rw- group::r-- other::r-- # file: file1.txt # owner: jeffrin # group: jeffrin user::rw- group::r-- other::r-- # file: file2.txt # owner: jeffrin # group: jeffrin user::rw- group::r-- other::r-- $chmod 777 file2.txt $ls -l file2.txt -rwxrwxrwx 1 jeffrin jeffrin 6 Jan 22 22:44 file2.txt $setfacl --restore=permissions.txt $ls -l file2.txt -rw-r--r-- 1 jeffrin jeffrin 6 Jan 22 22:44 file2.txt $
simple hack using the “join” command
$cat name.txt 1 ram 2 shyam 3 raju 4 biju $cat company.txt 1 google 2 facebook 3 twitter 4 ibm $join company.txt name.txt 1 google ram 2 facebook shyam 3 twitter raju 4 ibm biju $join name.txt company.txt 1 ram google 2 shyam facebook 3 raju twitter 4 biju ibm $
sample session with “ss” command to show details on network
$ss -t State Recv-Q Send-Q Local Address:Port Peer Address:Port ESTAB 0 0 192.168.0.100:57982 216.58.197.34:https ESTAB 0 0 192.168.0.100:56572 216.58.196.98:https ESTAB 0 0 192.168.0.100:51440 216.58.220.34:https ESTAB 0 0 192.168.0.100:56850 216.58.196.110:https ESTAB 0 0 192.168.0.100:42946 216.58.220.46:https ESTAB 0 0 192.168.0.100:42758 216.58.197.46:https ESTAB 0 0 192.168.0.100:32912 216.58.220.33:https ESTAB 0 0 192.168.0.100:40452 216.58.220.38:https ESTAB 0 0 192.168.0.100:51128 182.79.251.80:https ESTAB 0 0 192.168.0.100:38490 216.58.220.35:https ESTAB 0 0 192.168.0.100:37378 216.58.196.97:https ESTAB 0 0 192.168.0.100:41954 216.58.196.100:https CLOSE-WAIT 1 0 192.168.0.100:43954 74.125.100.153:https ESTAB 0 0 192.168.0.100:42908 216.58.197.74:https ESTAB 0 0 192.168.0.100:37384 216.58.196.97:https ESTAB 0 0 192.168.0.100:56818 216.58.196.110:https ESTAB 1430 0 192.168.0.100:51130 182.79.251.80:https $ss -s Total: 875 (kernel 0) TCP: 22 (estab 16, closed 1, orphaned 0, synrecv 0, timewait 1/0), ports 0 Transport Total IP IPv6 * 0 - - RAW 1 0 1 UDP 17 15 2 TCP 21 19 2 INET 39 34 5 FRAG 0 0 0 $