bash - check if file is png file using magic numbers
Bash[Edit]
+
0
-
0
Bash - check if file is PNG file using magic numbers
1[ "$(xxd -s 0 -l 4 -p "/path/to/image.png")" = "89504e47" ] && echo "image.png is PNG file" || echo "image.png is not PNG file"
[Edit]
+
0
-
0
Bash - check if file is PNG file using magic numbers
1 2 3 4 5 6if [ "$(xxd -s 0 -l 4 -p "/path/to/image.png")" = "89504e47" ] then echo "image.png is PNG file" else echo "image.png is not PNG file" fi
[Edit]
+
0
-
0
Bash - check if file is PNG file using magic numbers
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20function is_png() # args: file_path { # . P N G (as chars) # 89504e47 (in hex) [ "$(xxd -s 0 -l 4 -p "$1")" = "89504e47" ] && return 0 || return 1 } # Usage example: is_png "/path/to/image.png" && echo "image.png is PNG file" || echo "image.png is not PNG file" # or: if is_png "/path/to/image.png" then echo "image.png is PNG file" else echo "image.png is not PNG file" if