首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用find、file和upx的系统范围内的elf压缩脚本

使用find、file和upx的系统范围内的elf压缩脚本
EN

Stack Overflow用户
提问于 2012-08-03 09:51:38
回答 2查看 687关注 0票数 1

我正在编写我的第一个脚本,它是压缩系统上的所有elf可执行文件。

代码语言:javascript
复制
  find / * -executable -type f -exec file '{}' \; | grep ELF | sed -e "s/[:].*//" |     
  upx --best --ultra-brute 

upx不响应已发送的文件

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-08-03 16:29:45

我不确定你的系统是否安全(你不想至少过滤共享库吗?),但我建议:

代码语言:javascript
复制
find / -executable -type f | xargs file |\
grep ELF | cut -d: -f1 | xargs upx --best --ultra-brute

如果文件名中有空格

代码语言:javascript
复制
find / -executable -type f -print0 | xargs -0 file |\
grep ELF | cut -d: -f1 | xargs -0 upx --best --ultra-brute

但很可能会遇到shell限制(xargs:参数行太长)

一种解决方法是使用循环:

代码语言:javascript
复制
find / -executable -type f -print0 | xargs -0 file |\
grep ELF | cut -d: -f1 |\
while read f 
do
   upx --best --ultra-brute "$f"
done
票数 2
EN

Stack Overflow用户

发布于 2012-08-03 16:14:42

您需要在exec参数中包含管道。我用sh -c做到了这一点

代码语言:javascript
复制
find / * -executable -type f -exec sh -c 'file '{}' \
| grep -q ELF' \; -print \
| upx --best --ultra-brute 

另外,我在这里使用的是-print,而不是你用sed构建的代码。这样做更好,因为如果文件名中包含:,则基于sed的解决方案将不起作用(带有xargs -0-print0会更好)。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11788204

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档