Anon 06/25/2024 (Tue) 13:23 No.10549 del
I emitted thousands of random extensionless files (incl. these 5). For certain reasons, I now want to add extensions to them. They are .gif, .png, .swf, etc.; use this:
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:
. ipfs://bafkreiap6ghxpyd7hx5cvy3xvebbf5zzn57zotq53wzjwnktgcebti72ee
. https://yukovskibot.com/wV6Ne-DGnCERDnCeFVm7XPhnRFhMB_g9nvcYwThutzY
. based on https://www.baeldung.com/linux/bash-add-file-extension

Problem with that (if you don't put the them in 1000-files folders or something):
>bash: line 1: [: too many arguments
So I can go back to my "crappy" solution which I wrote before I saw that baeldung.com page:
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.

>>10547
>I've found hidden gems on those from that unsurpassed creative drive.
Made me check something - this YouTube video which has 4 likes in Twibooru
https://twibooru.org/3229570?q=derpibooru_id:3365361

Message too long. Click here to view full text.