I am trying to print all of the program file names on a system accessable from bash. (eg the path) I have been using 'which $(compgen -c)' but that does not seem efficient. Is there a better way?
I am trying to print all of the program file names on a system accessable from bash. (eg the path) I have been using 'which $(compgen -c)' but that does not seem efficient. Is there a better way?
This seems faster:
And this isn't faster but it prints accurately the commands found in the filesystem and only printing one path for every name depending on which would get executed first, not twice e.g. if
/bin/echo
and/usr/bin/echo
both exist would only print either of the two. It could happen sincecompgen -c
doesn't only print theecho
found in the filesystem but theecho
builtin command as well. The command above would print all executables found in$PATH
.If your commands has spaces, use
IFS=$'\n'
in a subshell:Disabling pathname expansion could also be safer:
Saving to an array as well: