Have you ever mashed away at 70 to 120 words per minute (or more or less) on your linux box – OR as I like to call hacking – OR sometimes linuxing – and then of the blue… Brain Freeze! (and not from your ice-cream your eating)… But… You simply cant remember a command… On top of that your too lazy to open up a browser and google it (as it might require some keyboarding – unless your familiar with w3m or whatever cli browser is out there).

Well lucky for us there is a command, that I like to think of it like the “?” command with Netgear/HP/Cisco interfaces. Where it just lists all of the commands. Unlike the awesome “?” this command will not go further than the command name, for example the arguments  – you will not find those out with this command. You will need to use –help. OR use “man your-forgotten-command” (which you just remember because you used this helpful trick of a command).

Dun… dun… dun…

compgen -c

Ill show you the output of all that later. compgen -c literally lists all of the commands – bash and all executable files that are found in your echo $PATH 

 

EXERPT FROM STACKEXCHANGE

CITATION: This section is an exerpt from the top comment : http://unix.stackexchange.com/questions/151118/understand-compgen-builtin-command by user cuonglm

Options for compgen command are the same as complete, except -p and -r. From compgen man page:

compgen
 compgen [option] [word]
 Generate possible completion matches for word according to the options, which 
 may be any option accepted by the complete builtin with the exception of -p 
 and -r, and write the matches to the standard output

For options [abcdefgjksuv]:

  • -a means Names of alias
  • -b means Names of shell builtins
  • -c means Names of all commands  <— this is what I use 🙂
  • -d means Names of directory
  • -e means Names of exported shell variables
  • -f means Names of file and functions
  • -g means Names of groups
  • -j means Names of job
  • -k means Names of Shell reserved words
  • -s means Names of service
  • -u means Names od userAlias names
  • -v means Names of shell variables

You can see complete man page here.

 

BACK TO MY OWN MATERIAL

Output of compgen -c (I usually like to sort it) – yah here is all my commands I dont care if you hack this box (as you dont know which box this is bwahaha)

# compgen -c | sort
:
!
.
[
[
[[
]]
{
}
2to3
2to3-2.6
2to3-2.7
2to3-3.2
7z
7za7
a2dismod
a2dissite
a2enmod
a2ensite
a2p
ab
accessdb
acpid
acpi_listen
addgroup
addpart
addr2line
add-shell
adduser
afpd
agetty
alias
apache2
apache2ctl
apachectl
apr-1-config
apr-config
apropos
apt
apt-cache
apt-cdrom
apt-config
apt-file
apt-get
apt-key
apt-mark
apt_wait
apu-1-config
apu-config
apxs2
ar
arch
arp
arpd
as
attr
autossh
autossh-argv0
avahi-daemon
awk
backup_md
badblocks
base64
basename
bash
bashbug
bg
bind
bison
bison.yacc
bit_rot_event
blkid
blkmapd
blockdev
break
bsd-from
bsdtar
bsd-write
bsinfoI
bsinfoP
btrfs
btrfsck
btrfs-convert
btrfs-debug-tree
btrfs-find-root
btrfs-image
btrfs-map-logical
btrfs-select-super
btrfs-show-super
btrfstune
btrfs-zero-log
builtin
bundle
bundler
bunzip2
busybox
bzcat
bzcmp
bzdiff
bzegrep
bzexe
bzfgrep
bzgrep
bzip2
bzip2recover
bzless
bzmore
c++
c2ph
c89
c89-gcc
c99
c99-gcc
CACTI_rebuild_polled_cache.sh
cal
calendar
caller
captoinfo
case
cat
catchsegv
catman
cc
cd
cfdisk
c++filt
cgdisk
chacl
chacl
chage
chattr
chcon
check_forensic
checkgid
check_ups_drv
cheetah
cheetah-analyze
cheetah-compile
chfn
chgpasswd
chgrp
chkdupexe
chmod
chown
chpasswd
chroot
chroot
chrt
chsh
cifscreds
cifsiostat
cifs.upcall
cksfv
cksum
clear
clear_console
cmp
cnid_dbd
cnid_metad
col
colcrt
colrm
column
comm
command
compgen
compile_et
complete
compopt
compose
config_data
connmanctl
connmand
continue
coproc
corelist
cp
cpan
cpan2dist
cpanp
cpanp-run-perl
cpgr
cpio
cpp
cpp-4.7
cppw
create_bond
c_rehash
cron
crontab
cryptsetup
csplit
ctrlaltdel
ctstat
curl
curl-config
curlip
cut
cytune
dash
date
dbd
dbilogstrip
dbiprof
dbus-cleanup-sockets
dbus-daemon
dbus-monitor
dbus-run-session
dbus-send
dbus-uuidgen
dd
ddate
ddf
debconf
debconf-apt-progress
debconf-communicate
debconf-copydb
debconf-escape
debconf-set-selections
debconf-show
deb-systemd-helper
deb-systemd-invoke
debugfs
declare
delgroup
delpart
deluser
depmod
df
dh_numpy
dh_perl_dbi
dh_pysupport
dh_python2
dh_python3
diff
diff3
diffindex-download
diffindex-rred
dir
dircolors
dirname
dirs
disk_chan
disk_event_handler
disks
disown
dmesg
dmsetup
dnsdomainname
do
domainname
done
dos2unix
dosfsck
dosfslabel
dpkg
dpkg-architecture
dpkg-buildflags
dpkg-buildpackage
dpkg-checkbuilddeps
dpkg-deb
dpkg-distaddfile
dpkg-divert
dpkg-divert
dpkg-genchanges
dpkg-gencontrol
dpkg-gensymbols
dpkg-maintscript-helper
dpkg-mergechangelogs
dpkg-name
dpkg-parsechangelog
dpkg-preconfigure
dpkg-query
dpkg-reconfigure
dpkg-scanpackages
dpkg-scansources
dpkg-shlibdeps
dpkg-source
dpkg-split
dpkg-statoverride
dpkg-statoverride
dpkg-trigger
dpkg-vendor
dprofpp
dropbearmulti
du
dumpe2fs
dumpsexp
e2freefrag
e2fsck
e2image
e2label
e2undo
e4defrag
easy_install
easy_install-2.6
easy_install-2.7
easy_install3
echo
echo
edit
editor
egrep
egrep
elfedit
elif
else
enable
enc2xs
encode_keychange
env
eqn
erb
esac
ethtool
eval
eventlogadm
event_push
ex
exec
exit
expand
expiry
export
exportfs
expr
f2py
f2py2.6
f2py2.7
factor
faillog
fallocate
false
false
fc
fc-cache
fc-cat
fc-list
fc-match
fc-pattern
fc-query
fc-scan
fdformat
fdisk
ffmpeg
ffprobe
fg
fgrep
fi
file
filefrag
find
find2perl
findfs
findmnt
firmware_update
FIXALLMAINPERMS.sh
fixparts
FIXPERMSDOWNLOADS.sh
fixperms-guest-guest.sh
fixperms-infotinks-users.sh
fixproc
flock
fmt
fold
for
forked-daapd
free
freetype-config
from
fsck
fsck.btrfs
fsck.cramfs
fsck.ext2
fsck.ext3
fsck.ext4
fsck.ext4dev
fsck.minix
fsck.msdos
fsck.nfs
fsck.vfat
fsfreeze
fstab-decode
fstrim
function
fuser
fusermount
g++
g++-4.7
gcc
gcc-4.7
gcc-ar
gcc-ar-4.7
gcc-nm
gcc-nm-4.7
gcc-ranlib
gcc-ranlib-4.7
gcov
gcov-4.7
gdisk
gem
gencat
geqn
getconf
get_disk_info
getent
getfacl
getfacl
getfattr
getopt
getopts
get_psu_info
getty
git
git-receive-pack
git-shell
git-upload-archive
git-upload-pack
gold
gpasswd
gpg
gpg-error
gpg-error-config
gpgsplit
gpgv
gpg-zip
gpic
gprof
grep
grep
groff
grog
grops
grotty
groupadd
groupdel
groupmod
groups
grpck
grpconv
grpunconv
gss_clnt_send_err
gss_destroy_creds
gtbl
gunzip
gzexe
gzip
h2ph
h2xs
halt
hash
hashdeep
hd
hdparm
head
heimdall
help
helpztags
hexdump
hexedit
history
hmac256
host
hostid
hostname
hotplug_event
htcacheclean
htdigest
htop
htpasswd
httxt2dbm
hwclock
i386
iconv
iconvconfig
id
if
ifconfig
ifenslave
ifenslave-2.6
iftop
in
infocmp
infotocap
init
innochecksum
innotop
inotifywait
inotifywatch
insmod
insserv
install
install-info
instmodsh
invoke-rc.d
ionice
ioping
iostat
iotop
ip
ip
ip6tables
ip6tables-apply
ip6tables-restore
ip6tables-save
ipcmk
ipcrm
ipcs
ipmaddr
iptables
iptables-apply
iptables-restore
iptables-save
iptables-xml
iptraf
iptunnel
irb
ischroot
isosize
jobs
join
journalctl
json_pp
kill
kill
killall
killall5
krb5-config
l
last
lastb
lastlog
lcf
ld
ldattach
ld.bfd
ldconfig
ldconfig.real
ldd
ld.gold
less
let
lexgrog
libgcrypt-config
libnetcfg
line
link
linux32
linux64
ll
ln
lnstat
local
locale
localedef
logger
login
loginctl
logname
logout
logresolve
logsave
look
LOOPRTUNRAR.sh
lorder
losetup
lowntfs-3g
ls
ls
lsattr
lsblk
lscpu
lsmod
lsmod
lsof
lspgpot
lsyncd
lua
lua5.1
luac
luac5.1
luksformat
lzcat
lzcmp
lzdiff
lzegrep
lzfgrep
lzgrep
lzless
lzma
lzmainfo
lzmore
m4
mac2unix
macusers
make
man
mandb
manpath
mapfile
mawk
mc
mcdiff
mcedit
mcookie
mcview
md5deep
md5sum
md5sum.textutils
mdadm
mdadm-startall
mdcsrepair
mdcsrepaird
md_event
mdmon
mesg
mii-tool
minidlnad
minissdpd
mkdir
mkdosfs
mke2fs
mkfifo
mkfs
mkfs.bfs
mkfs.btrfs
mkfs.cramfs
mkfs.ext2
mkfs.ext3
mkfs.ext4
mkfs.ext4dev
mkfs.hfsplus
mkfs.minix
mkfs.msdos
mkfs.ntfs
mkfs.vfat
mkhomedir_helper
mkhomedir_helper
mklost+found
mknod
mkntfs
mkswap
mktemp
mlock
modinfo
modprobe
more
mostfragged.sh
mount
mountall.sh
mount.cifs
mount.fuse
mountHfromCEO.sh
mount.lowntfs-3g
mount.nfs
mount.nfs4
mount.ntfs
mount.ntfs-3g
mountpoint
mountstats
mpstat
msmtp
msmtpq
msql2mysql
mtrace
mv
myisamchk
myisam_ftdump
myisamlog
myisampack
my_print_defaults
mysql
mysqlaccess
mysqladmin
mysqlanalyze
mysqlbinlog
mysqlbug
mysqlcheck
mysql_client_test
mysql_config
mysql_convert_table_format
mysqld
mysqld_multi
mysqld_safe
mysqldump
mysqldumpslow
mysql_find_rows
mysql_fix_extensions
mysqlhotcopy
mysqlimport
mysql_install_db
mysqloptimize
mysql_plugin
mysqlrepair
mysqlreport
mysql_secure_installation
mysql_setpermission
mysqlshow
mysqlslap
mysqltest
mysql_tzinfo_to_sql
mysql_upgrade
mysql_waitpid
mysql_zap
namei
nameif
nano
nano
nawk
ncal
ncat
ncftp
ncftp3
ncftpbatch
ncftpget
ncftpls
ncftpput
ncftpspooler
ncurses5-config
ncursesw5-config
ndiff
neqn
net
netatalk
nethogs
net-snmp-config
netstat
newgrp
newusers
nfnl_osf
nfsidmap
nfsiostat
nfsiostat
nfsstat
nice
nisdomainname
nl
nm
nmap
nmbd
nmblookup
noflushd
nohup
nokogiri
nologin
notify_ups
nping
nproc
nroff
nslookup
nstat
ntdbbackup
ntdbdump
ntdbrestore
ntdbtool
ntfs-3g
ntfs-3g.probe
ntfs-3g.secaudit
ntfs-3g.usermap
ntfscat
ntfsck
ntfsclone
ntfscluster
ntfscmp
ntfscp
ntfsdecrypt
ntfsdump_logfile
ntfsfix
ntfsinfo
ntfslabel
ntfsls
ntfsmftalloc
ntfsmove
ntfsresize
ntfstruncate
ntfsundelete
ntfswipe
ntlm_auth
ntpdate
objcopy
objdump
od
oldfind
openssl
osd_login
pager
pam-auth-update
pam_getenv
pam_tally
pam_tally2
partx
passwd
paste
patch
pathchk
pcre-config
pdb
pdb2.6
pdb2.7
pdb3
pdb3.2
pdbedit
pear
peardev
pecl
peekfd
perl
perl5.14.2
perlbug
perldoc
perlivp
perlthanks
perror
pg
pg_config
pgrep
php
php5
php5dismod
php5enmod
pic
pico
piconv
pidof
pidstat
ping
ping6
pinky
pip
pip-2.6
pip-2.7
pip-3.2
pivot_root
pkg-config
pkill
pl2pm
plipconfig
pmap
pod2html
pod2latex
pod2man
pod2text
pod2usage
podchecker
podselect
popd
powerbtn
poweroff
pr
preconv
prename
print
printenv
printerbanner
printf
printf
profiles
proftpd
prove
prtstat
ps
psed
pstree
pstruct
ptar
ptardiff
ptargrep
ptx
pushd
pv
pwauth
pwck
pwconv
pwd
pwd
pwdx
pwunconv
py3clean
py3compile
py3versions
pyclean
pycompile
pydoc
pydoc2.6
pydoc2.7
pydoc3
pydoc3.2
pygettext
pygettext2.6
pygettext2.7
pygettext3
pygettext3.2
python
python2
python2.6
python2.7
python3
python3.2
python3.2mu
python3mu
pyversions
qt-faststart
radar
raidar
raidard
rake
ranlib
rapt-file
rar
rarp
raw
rbash
rcp
rdoc
read
readarray
readelf
readlink
readonly
readprofile
readydropd
readydrop-dbini
readyinfo
readynas-agent
readynasd
readyNASVault
readyNASVaultDaemon
readytivod
reboot
regexp-assemble
remote_access
remove-shell
rename
rename.movies.files.dry
rename.movies.files.dry.not
rename.movies.folders.dry
rename.movies.folders.dry.not
rename.ul
renice
REPEATING-RTUNRAR2NFIX.sh
replace
reset
resize2fs
resolveip
resolve_stack_dump
return
rev
rgrep
ri
rlogin
rm
rmdir
rmmod
rmt
rmt-tar
rnano
rn_lcd
rn_nml
rnotifyd
rn_shutdown
rnutil
rotatelogs
route
routef
routel
rpcbind
rpcclient
rpcdebug
rpcgen
rpc.gssd
rpc.idmapd
rpcinfo
rpcinfo
rpc.mountd
rpc.nfsd
rpc.statd
rpc.svcgssd
rrdcgi
rrdtool
rrdupdate
rscreen
rsh
rsync
rtacct
rtcwake
rtmon
rtmux
rtstat
RTUNRAR2NFIX.sh
rtunzip-any-currentfolder-deletezipsnrars.sh
rtunzip-any-currentfolder.sh
rtunzip-rtfolder.sh
ruby
runcon
runlevel
run-mailcap
run-parts
ruscreen
rview
rvim
rvnamed
s2p
sadf
sar
sar.sysstat
savelog
scp
screen
script
scriptreplay
scsi_logging_level
scsi_mandat
scsi_readcap
scsi_ready
scsi_satl
scsi_start
scsi_stop
scsi_temperature
sdiff
search_for_key
sed
see
select
sendmail
sensible-browser
sensible-editor
sensible-pager
seq
service
set
setarch
setfacl
setfacl
setfattr
set_mtu
setsid
setterm
sfdisk
sftp
sg
sg_dd
sg_decode_sense
sgdisk
sg_emc_trespass
sg_format
sg_get_config
sg_get_lba_status
sg_ident
sginfo
sg_inq
sg_logs
sg_luns
sg_map
sg_map26
sgm_dd
sg_modes
sg_opcodes
sgp_dd
sg_persist
sg_prevent
sg_raw
sg_rbuf
sg_rdac
sg_read
sg_read_block_limits
sg_read_buffer
sg_readcap
sg_read_long
sg_reassign
sg_referrals
sg_requests
sg_reset
sg_rmsn
sg_rtpg
sg_safte
sg_sanitize
sg_sat_identify
sg_sat_phy_event
sg_sat_set_features
sg_scan
sg_senddiag
sg_ses
sg_start
sg_stpg
sg_sync
sg_test_rwbuf
sg_turs
sg_unmap
sg_verify
sg_vpd
sg_write_buffer
sg_write_long
sg_write_same
sg_wr_mode
sh
sha1deep
sha1sum
sha224sum
sha256deep
sha256sum
sha384sum
sha512sum
shadowconfig
shasum
sh.distrib
shift
shopt
showmount
shred
shuf
shutdown
shutdown_eda
size
skill
slabtop
slattach
sleep
slogin
smartctl
smbcacls
smbclient
smbcontrol
smbcquotas
smbd
smbget
smbpasswd
smbspool
smbstatus
smbtar
smbtree
sm-notify
snapper
snapperd
snice
snmpbulkget
snmpbulkwalk
snmpconf
snmpd
snmpdelta
snmpdf
snmpget
snmpgetnext
snmpinform
snmpnetstat
snmpset
snmpstatus
snmptable
snmptest
snmptranslate
snmptrap
snmptrapd
snmpusm
snmpvacm
snmpwalk
soelim
sort
sotruss
source
spacewatch-part.sh
spacewatch.sh
spindown_schedule
splain
split
split-logfile
sprof
sqlite3
ss
ssh
ssh2debikos
ssh2ram
ssh-add
ssh-agent
ssh-argv0
ssh-copy-id
sshd
sshfs
ssh-keygen
ssh-keyscan
ssh-vulnkey
starlord-backup.sh
startpar
startpar-upstart-inject
start_raids
start-statd
start-stop-daemon
stat
stdbuf
strings
strip
stty
su
sudo
sudoedit
sudoreplay
sulogin
sum
supportshell
suspend
swaplabel
swapoff
swapon
switch_root
sync
sysctl
systemctl
systemd
systemd-analyze
systemd-ask-password
systemd-cat
systemd-cgls
systemd-cgtop
systemd-inhibit
systemd-machine-id-setup
systemd-notify
systemd-nspawn
systemd-stdio-bridge
systemd-tmpfiles
systemd-tty-ask-password-agent
tabs
tac
tail
tailf
tar
taskset
tbl
tc
tclsh
tclsh8.5
tclsh-default
tcltk-depends
tee
telinit
telnet
telnet.netkit
tempfile
test
test
testparm
testrb
tftp
then
tic
tigerdeep
time
timeout
times
tload
tmux
toe
top
touch
touch
tput
tr
transmission-cli
transmission-create
transmission-daemon
transmission-edit
transmission-remote
transmission-show
trap
traptoemail
treesize
troff
TRTUNRAR2NFIX.sh
true
true
truncate
tset
tsort
tty
tune2fs
tunelp
TUNRAR2NFIX.sh
type
typeset
tzconfig
tzselect
ucf
ucfq
ucfr
udevadm
udevd
udhcpc
ul
ulimit
ulockmgr_server
umask
umount
umountall.sh
umountHfromCEO.sh
umount.nfs
umount.nfs4
unalias
uname
uncompress
unexpand
uniq
unix2dos
unix2mac
unix_chkpwd
unix_update
unlink
unlzma
unrar
unrar1samedir-delete-rars.sh
unrar1samedir.sh
unrar2extracted-delete-rars.sh
unrar2extracted.sh
UNRAR2NFIX.sh
unrar3todir-delete-rars.sh
unrar3todir.sh
unset
unshare
until
unxz
unzip
update-alternatives
update-alternatives
update-ca-certificates
update-mime-database
update-mime-database.real
update-passwd
update-python-modules
update-rc.d
update-smart-drivedb
upnphttpd
upsc
upscmd
upsd
upsdrvctl
upslog
upsmon
upsrw
upssched
upssched-cmd
uptime
useradd
userdel
usermod
users
uuid
uuidgen
vdir
vi
vi
view
vigr
vim777
vim.basic
vimdiff
vim.tiny
vimtutor
vipw
virtualenv
visudo
vmstat
volume_schedule
volume_util
w
wait
wall
watch
WATCH-RTOR.sh
wbinfo
wc
wget
whatis
whereis
which
which
while
whirlpooldeep
who
whoami
winbindd
wipefs
wish
wish8.5
wish-default
w.procps
write
x86_64
x86_64-linux-gnu-cpp
x86_64-linux-gnu-cpp-4.7
x86_64-linux-gnu-g++
x86_64-linux-gnu-g++-4.7
x86_64-linux-gnu-gcc
x86_64-linux-gnu-gcc-4.7
x86_64-linux-gnu-gcc-ar-4.7
x86_64-linux-gnu-gcc-nm-4.7
x86_64-linux-gnu-gcc-ranlib-4.7
xargs
xmlindent
XRARDELRARFIXPERMS-guest-guest.sh
XRARDELRARFIXPERMS-infotinks-users.sh
xsubpp
xtables-multi
xxd
xz
xzcat
xzcmp
xzdiff
xzegrep
xzfgrep
xzgrep
xzless
xzmore
yacc
yes
youtube-dl
ypdomainname
zcat
zcmp
zdiff
zdump
zegrep
zfgrep
zforce
zgrep
zic
zip
zless
zmore
znew
zsoelim

NOTE: some commands appear twice as it shows all commands from PATH and all of the built in commands from the shell (/bin/bash) in my case

FINDING COMMANDS WITH COMPGEN

Wow thats alot. As you can imagine you can use it with grep.

I remember some command has the word disk in it.

# compgen -c | grep -i disk
disks
disk_chan
disk_event_handler
get_disk_info
gdisk
cgdisk
fdisk
cfdisk
sfdisk
sgdisk

Awesome now I remember my command was cfdisk. Cool now if I dont remember the arguments for cfdisk. I can just do cfdisk -h  or cfdisk –help  or man cfdisk  or google for “how I use cfdisk” or “cfdisk examples” or “cfdisk man page

Now compgen -c comes with a sort of find feature by it self. If you remember the beginning of the command. For example I remember my command starts with disk

# compgen -c disk
disks
disk_chan
disk_event_handler

Caveat of using it with the above method: Notice it didnt find any of the command’s where disk was in the middle. So I prefer to use disk

SUMMARY

If you cant think of a command run compgen -c  or compgen -c | grep what-you-remember-the-command-has

 

Leave a Reply

Your email address will not be published. Required fields are marked *