find . -type f -not -name "*.*" -exec bash -c \ 'if [ $(file --mime-type -b {}) == "image/jpeg" ]; then mv {} {}.jpg; fi;' \;; \ find . -type f -not -name "*.*" -exec bash -c \ 'if [ $(file --mime-type -b {}) == "image/png" ]; then mv {} {}.png; fi;' \;; [...]Full command:
cat cids.txt | xargs -d "\n" bash -c 'for args do file /ipfs/$args | \ sed "s/,.*//g" | grep -v ": data$"; done' _ | xargs -d "\n" sh -c \ 'for args do in=$(echo $args | sed "s/:.*//g"); ext=$(echo $args | \ sed "s/ image data//g" | sed "s/.* //g" | sed "s/GIF/gif/g" | \ sed "s/JPEG/jpg/g" | sed "s/PNG/png/g"); echo -n "$in "; \ echo $(echo $in | sed "s/.*\///g").$ext; done' _It doesn't have that too-many-args problem because it's streamed and not all at once. Or do this for jpg+gif+png:
find . -type f | xargs -d "\n" bash -c 'for args do tb=$(head \ -c 3 "$args" | xxd -p); if [ "$tb" == "ffd8ff" ]; then mv -n "$args" \ "$args.jpg"; fi; if [ "$tb" == "474946" ]; then mv -n "$args" "$args.gif"; \ fi; if [ "$tb" == "89504e" ]; then mv -n "$args" "$args.png"; fi; done' _That's based on the first bytes of files and not MIME type as determined by this program: file version 5.41. With file-5.41, I can add .txt; can't easily do that with top bytes.
Message too long. Click here to view full text.