On 4/3/23 10:58, Emanuel Berg wrote:
David Christensen wrote:

# echo $PATH | tr ':' '\n' | perl -MFile::Slurp -ne
    'chomp;@e=read_dir($_,prefix=>1); print map "$_\n",@e'|xargs
    file|perl -pe 's/\S+\s+//'|grep -v 'symbolic link'|perl -pe
    's/, dynamically linked.+//'|sort|uniq -c|sort -rn

I'm still so impressed by this, I tried to run this but it
seems I lack the Slurp module?


# apt-get install libfile-slurp-perl


Also, if it isn't too much to ask, can you put it in the form
of a script or shell function the way you would? It doesn't
feel right for me to "indent your code" if you follow ...


2023-04-03 12:41:57 dpchrist@taz ~
$ cat bin/survey-path-file
#!/bin/sh
# $Id: survey-path-file,v 1.3 2023/04/03 19:41:56 dpchrist Exp $
# by David Paul Christensen dpchr...@holgerdanske.com
# Public Domain
#
# Run file(1) for files in PATH.  Count and print frequency of results.

echo $PATH \
| tr ':' '\n' \
| perl -MFile::Slurp -ne 'chomp;print map {"$_\n"} read_dir($_,prefix=>1)' \
| xargs file \
| perl -pe 's/\S+\s+//' \
| grep -v 'symbolic link' \
| perl -pe 's/, dynamically linked.+//' \
| sort \
| uniq -c \
| sort -rn

2023-04-03 12:41:59 dpchrist@taz ~
$ survey-path-file
   1490 ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV)
    290 POSIX shell script, ASCII text executable
    145 Perl script text executable
     40 Python script, ASCII text executable
     24 setuid ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV)
     18 ELF 64-bit LSB executable, x86-64, version 1 (SYSV)
     18 Bourne-Again shell script, ASCII text executable
     14 setgid ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV)
     14 Tcl script, ASCII text executable
      8 POSIX shell script, UTF-8 Unicode text executable
      6 ELF 64-bit LSB pie executable, x86-64, version 1 (GNU/Linux)
      4 Python script, UTF-8 Unicode text executable
      2 a /usr/bin/env sh script, ASCII text executable
      2 a /bin/mksh script, UTF-8 Unicode text executable
      2 Python script, ISO-8859 text executable
      2 POSIX shell script, ASCII text executable, with very long lines
      2 Java source, UTF-8 Unicode text
      2 ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux)


David

Reply via email to