[英]system wide elf compression script using find, file, and upx
I'm working on my first script, and it is to compress all elf executables on a system. 我正在处理我的第一个脚本,它是压缩系统上的所有elf可执行文件。
find / * -executable -type f -exec file '{}' \; | grep ELF | sed -e "s/[:].*//" |
upx --best --ultra-brute
upx is not responding to sent files upx没有响应发送的文件
Not sure if you're going a safe way for your system (don't you want to filter at least shared libs?), but I would suggest: 不确定你是否为你的系统安全(你不想过滤至少共享库吗?),但我建议:
find / -executable -type f | xargs file |\
grep ELF | cut -d: -f1 | xargs upx --best --ultra-brute
If you have blanks in file names 如果文件名中有空格
find / -executable -type f -print0 | xargs -0 file |\
grep ELF | cut -d: -f1 | xargs -0 upx --best --ultra-brute
but is is likely you will bump into a shell limit (xargs: argument line too long) 但很可能你会碰到一个shell限制(xargs:参数行太长)
One workaround would be to use a loop: 一种解决方法是使用循环:
find / -executable -type f -print0 | xargs -0 file |\
grep ELF | cut -d: -f1 |\
while read f
do
upx --best --ultra-brute "$f"
done
You need to include pipe in the exec
argument. 您需要在
exec
参数中包含管道。 I do that with sh -c
: 我用
sh -c
这样做:
find / * -executable -type f -exec sh -c 'file '{}' \
| grep -q ELF' \; -print \
| upx --best --ultra-brute
Also I use here -print
instead of your construction with sed
. 另外我在这里使用
-print
而不是你的sed
。 It's better because in case you have :
in a filename, sed-based solution will not work (even better is -print0
with xargs -0
). 它更好,因为如果你有
:
在文件名中,基于sed的解决方案将无法工作(更好的是-print0
与xargs -0
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.