سؤال

I'm working on my first script, and it is to compress all elf executables on a system.

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

upx is not responding to sent files

هل كانت مفيدة؟

المحلول

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)

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. I do that with 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. It's better because in case you have : in a filename, sed-based solution will not work (even better is -print0 with xargs -0).

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top