4 years ago I wrote a script called FindMagic to identify
executable files using hexdump and magic numbers.
Yesterday I used it to list all of the Tinycore scripts in /usr/bin/
for a forum member:
tc@E310:~$ ls -1 /usr/bin/ | while read F; do ./FindMagic /usr/bin/$F 2>&1 | grep Script; done
Script /usr/bin/backup
Script /usr/bin/bbcheck.sh
Script /usr/bin/bigHomeFiles.sh
Script /usr/bin/calc
Script /usr/bin/chkonboot.sh
----- Snip -----
It occurred to me it should be able to handle multiple files in one
shot natively instead of calling the script multiple times, like this:
tc@E310:~$ ls -d /usr/bin/* | ./FindMagic | grep Script
Script /usr/bin/backup
Script /usr/bin/bbcheck.sh
Script /usr/bin/bigHomeFiles.sh
Script /usr/bin/calc
Script /usr/bin/chkonboot.sh
----- Snip -----
So now it can handle multiple files from the command line or you
can pipe the data straight into the script:
tc@E310:~$ FindMagic
Written by Richard A. Rost Jun 11,2020
This script attempts to identify executable files by type.
Types are ELF32 ELF64 Script Win Dos Unknown
If type is Script, the first 3 lines of the script are printed.
Usage:
FindMagic Filename1 [ Filename2 Filename3 etc ]
ls | FindMagic
ls -d /Path/To/Files/* | FindMagic
tc@E310:~$
A copy of the script is attached so you can see how it's done.