Joh*_*mBF 7 bash find executable elf files
我想找到从内核的角度来看可执行的文件类型。据我所知,Linux 上的所有可执行文件都是 ELF 文件。因此,我尝试了以下操作:
find * | file | grep ELF
但是这不起作用;有人有其他想法吗?
fro*_*boo 12
稍后编辑:只有这个可以满足 jan 的需要:谢谢惠更斯;
find . -exec file {} \; | grep -i elf
对于有限(例如嵌入式)系统上的系统,不使用file
和 的替代解决方案:readelf
find $WHERE -type f -exec hexdump -n 4 -e '4/1 "%2x" " {}\n"' {} \; | grep ^7f454c46
Run Code Online (Sandbox Code Playgroud)
基本上,我们输出前四个字节并hexdump
使用它们作为签名。然后我们可以使用其签名来grep 所有ELF类型的文件7f454c46
。
或者,由于7f
是删除字符,45
, 4c
,46
字节分别是E
, L
,F
字符,我们也可以使用:
find $WHERE -type f -exec hexdump -n 4 -e '4/1 "%1_u" " {}\n"' {} \; | grep ^delELF
Run Code Online (Sandbox Code Playgroud)
head
另外,在这种情况下您可以使用hexdump
:
find $WHERE -type f -exec head -c 4 {} \; -exec echo " {}" \; | grep ^.ELF
Run Code Online (Sandbox Code Playgroud)