compgen -c | sort -b | uniq | less
Shows also functions and keywords (luckily no aliases), I instead want all that are not keywords, functions or aliases. In few words only the commands.
If command name match with function name, keyword name or alias name; the command name must not be omitted.
For
compgen
(and I think for Linux in general), a command is everything that you can run including alias' and functions, etc.If you want to get only executable files/scripts in any of your
$PATH
directories, there is no good way usingcompgen
.You could use
comm
to show all commands excluding aliases, keywords and functions:However, this will also remove commands that are both alias/function and command (e.g.
ls
orgrep
have an alias per default in Ubuntu, as well as anything you added yourself).So, I think you're better off getting all executables from
$PATH
with your own script (and if you wish you can addbuiltins
usingcompgen -b
):To print aliases, run:
To print functions, run:
or
To print commands ( excluding aliases, keywords and functions ), run:
grep -wv "$(alias | grep -oP '\w+(?=\=)')"
will exclude aliases.grep -wv "$(declare -F | awk '{print $3}')"
will exclude functions.grep -wFv "$(compgen -k)"
will exclude keywords.