Simple Script to Find All Commands
Posted: 02 Apr 2016, 23:39
Intrigued by a question on minichat, set about working this out. The script allcom.sh should hopefully cover 99% of commands. The output is a file of commands, including paths, to stdout. Invocation is clear from the two examples given with formatted output. The default has all commands up to a length of 8 characters.
Enjoy!
The question as to whether Porteus has more commands than Sackware and vice versa, could probably be answered by running the same script under Slackware, then using the sorted output of the distros, from up to a command length of 8, together with unique. Sed could also be used to get rid of the paths, but probably there is no need for this. Also one needs to bear in mind that root has different commands available to it than those of an ordinary user.
Enjoy!
Code: Select all
guest@porteus:~$ sh allcom.sh 1
/usr/bin/w
guest@porteus:~$ sh allcom.sh 2 | column -x
/usr/bin/w /usr/bin/ar /usr/bin/as /usr/bin/bc /usr/bin/cp
/usr/bin/dc /usr/bin/dd /usr/bin/df /usr/bin/du /usr/bin/id
/usr/bin/js /usr/bin/ld /usr/bin/ln /usr/bin/lp /usr/bin/ls
/usr/bin/mc /usr/bin/mv /usr/bin/nl /usr/bin/nm /usr/bin/od
/usr/bin/pg /usr/bin/pr /usr/bin/ps /usr/bin/rm /usr/bin/sg
/bin/sh /bin/su /usr/bin/tr /usr/bin/ul /usr/bin/vi
/usr/bin/wc /usr/bin/xx /usr/bin/xz /usr/bin/7z
Code: Select all
guest@porteus:~$ sh allcom.sh 3 | column -x
/usr/bin/w /usr/bin/ar /usr/bin/as
/usr/bin/bc /usr/bin/cp /usr/bin/dc
/usr/bin/dd /usr/bin/df /usr/bin/du
/usr/bin/id /usr/bin/js /usr/bin/ld
/usr/bin/ln /usr/bin/lp /usr/bin/ls
/usr/bin/mc /usr/bin/mv /usr/bin/nl
/usr/bin/nm /usr/bin/od /usr/bin/pg
/usr/bin/pr /usr/bin/ps /usr/bin/rm
/usr/bin/sg /bin/sh /bin/su
/usr/bin/tr /usr/bin/ul /usr/bin/vi
/usr/bin/wc /usr/bin/xx /usr/bin/xz
/usr/bin/7z /usr/bin/act /usr/bin/awk
/usr/bin/bat /usr/bin/bzz /usr/bin/cal
/usr/bin/cat /usr/bin/cgm /usr/bin/cjs
/usr/bin/cmp /usr/bin/col /usr/bin/cut
/usr/bin/cvt /usr/bin/c44 /usr/bin/dir
/usr/bin/dwp /usr/bin/env /usr/bin/eqn
/usr/bin/esd /usr/bin/fmt /usr/bin/gpg
/usr/bin/grn /usr/bin/gtf /usr/bin/idn
/usr/kerberos/bin/ksu /usr/bin/ldd /usr/bin/lex
/usr/bin/lpq /usr/bin/lpr /usr/local/bin/man
/usr/bin/mcd /usr/bin/mdu /usr/bin/mev
/usr/bin/mmd /usr/bin/mrd /usr/bin/net
/usr/bin/pic /usr/bin/ptx /usr/bin/pwd
/usr/bin/raw /usr/bin/rev /bin/rpm
/usr/bin/scp /usr/bin/sed /usr/bin/seq
/usr/bin/ssh /usr/bin/sum /usr/bin/tac
/usr/bin/tar /usr/bin/tbl /usr/bin/tee
/usr/bin/tic /usr/bin/toe /usr/bin/top
/usr/bin/tty /usr/bin/usm /usr/bin/vte
/usr/bin/who /usr/bin/xdm /usr/bin/xev
/usr/bin/yes /usr/bin/zip /usr/bin/7za
/usr/bin/7zg /usr/bin/7zr
Code: Select all
#!/bin/bash
# Simple Script to Find All Commands (Bogomips 03.04.2016)
# Invocation: sh allcom.sh <Length Limit of Commands>
# Default is a limiting length of 8. At a limit of 3 slowing down starts.
# Reccomend running when machine idle
# l = Limiting Length of Command
# i = # of cols c = Column Offset
# j = Iterator over Vector v m = Vector: Offset of v for given Column
com(){
local j; let j=0;
if ((c<i+1)); then
while ((j<n)); do
# echo $i $j $c
let m[c++]=j++; com;
done
let c--; return;
fi
# End of Line: String the Command
cmd=""; for ((k=0; k<i+1; k++)); do
cmd+=${v[m[k]]};
done
which $cmd 2>/dev/null; let c--;
return;
}
cmd(){
unset v;for a in {a..z} {0..9}; do v+=($a); done
# l = Length of Command Limit
# i = # of cols c = Column Offset
let n=${#v[*]};
unset m; let l=${1:-8};
for ((i=0; i<l; i++)); do let c=0; com; done
}
cmd $1