Skip to content

Instantly share code, notes, and snippets.

@pointhi
Created December 1, 2018 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pointhi/590ee986d47d483c9c7d35fae472c661 to your computer and use it in GitHub Desktop.
Save pointhi/590ee986d47d483c9c7d35fae472c661 to your computer and use it in GitHub Desktop.
find image files on a busybox machine (without using tools like file, ...)
#!/bin/sh
if [ $# -eq 0 ]
then
echo "Usage: $0 <search_root_dir>"
exit
fi
echo "------ start in directory: \"`pwd`/$1\""
find $1 -type f | while read fname; do
# match on Magic number of various image files
if hexdump -n8 "$fname" | grep -qF "0000000 5089 474e 0a0d 0a1a"; then
echo -ne "\nPNG MATCH: \"$fname\""
elif hexdump -n3 "$fname" | grep -qF "0000000 d8ff 00ff"; then
echo -ne "\nJPG MATCH: \"$fname\""
elif hexdump -n2 "$fname" | grep -qF "0000000 4d42"; then
echo -ne "\nBMP MATCH: \"$fname\""
else
echo -n "."
fi;
done
echo -e "\n------ end"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment