tags:

views:

154

answers:

1

How can I list all available UNIX commands from Perl?

+10  A: 
perl -MFile::Find -le 'find sub {print if -f and -x _}, split ":", $ENV{PATH}'

This code looks in each directory in your path (split ":", $ENV{PATH}) for files (-f) that are executable (-x), and prints the ones it finds. You may want to read about

An alternative that does not search subdirectories of the directories in the PATH is

perl -le '-f and -x _ and print for map { glob "$_/*" } split ":", $ENV{PATH}'
Chas. Owens
This will search subdirectories in `$PATH`, which is a bit unusual...
ephemient
@ephemient Good point, I don't normally see subdirectories in bin directories though.
Chas. Owens
My ~/bin is a git repository, there's a way to get subdirs in your bin directory.
Schwern