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
2009-07-15 13:01:44
This will search subdirectories in `$PATH`, which is a bit unusual...
ephemient
2009-07-15 15:00:17
@ephemient Good point, I don't normally see subdirectories in bin directories though.
Chas. Owens
2009-07-15 15:29:53
My ~/bin is a git repository, there's a way to get subdirs in your bin directory.
Schwern
2009-07-15 19:40:13