So I can enter
systemc and press Tab and get
But what if I want to list all commands that end in
How would I do that?
To list all available commands, including aliases, functions, bash builtins and bash keywords, use
compgen -c. You may
grep the resulting list with any pattern, for example:
compgen -c | grep 'ctl$'
If you use
apropos ctl | less you will see all of the commands containing the string ctl which include man pages. It will also display a few others containing that string but there is surprisingly few of these unintended results so you may find it quite useful.
There's nothing stopping you searching the
$PATH for matching files
( IFS=:; for p in $PATH; do ls -d "$p"/*ctl; done ) 2>/dev/null
I've used a subshell
( ... ) because I'm changing the shell variable
IFS. An alternative would be to save it at the beginning (
OIFS="$IFS" IFS=:) and restore it afterwards (
IFS="$OIFS") but to me this feels slightly less robust.
I would do this using
( IFS=:; for dir in $PATH; do find $dir/ -type f -executable -iregex ".*ctl"; done )
To show cmd's only:
( IFS=:; for dir in $PATH; do find $dir/ -type f -executable -iregex ".*ctl" -printf '%f\n'; done ) 2>/dev/null