Question

Do you have any pointer on how to write a script that will search my system for applications, libraries (i.e. /usr/local/lib and /usr/local), and binaries that are PPC only?

I upgraded my system from a PPC Mac to a Intel Mac running Leopard 10.5. Then I upgraded to Snow Leopard 10.6 which doesn't come with Rosetta. So I'm only now realising all the old PPC things that are left on my system!

Was it helpful?

Solution

The file command can detect what binary types are available in a file.

file -b /usr/bin/atrm
setuid Mach-O universal binary with 3 architectures
/usr/bin/atrm (for architecture x86_64): Mach-O 64-bit executable x86_64
/usr/bin/atrm (for architecture i386): Mach-O executable i386
/usr/bin/atrm (for architecture ppc7400): Mach-O executable ppc

So, then, it is just a matter of using find and filtering appropriately. Something like this should find all binaries on the system that have a PPC subsection.

find / -perm -u+x ! -type d -exec file {} \; | grep ppc | awk '{print $1}'

PPC only is a little more difficult. For that, you'll want to do three commands to create 2 files in /tmp, the first containing a list of PPC files and the second a list of 32 or 64 bit x86 files. Conveniently, 'ppc' matches ppc and ppc64.

find / -perm -u+x ! -type d -exec file {} \; | grep ppc | awk '{print $1}' > /tmp/ppc
find / -perm -u+x ! -type d -exec file {} \; | grep i386 | awk '{print $1}' > /tmp/x86
find / -perm -u+x ! -type d -exec file {} \; | grep x86_64 | awk '{print $1}' >> /tmp/x86

Then, sort/uniq a bit (just sorts the paths and makes sure each binary is only listed once):

cat /tmp/x86 | sort | uniq > /tmp/x86.filtered
cat /tmp/ppc | sort | uniq > /tmp/ppc.filtered

Then, use diff (and a bit more processing) to spew the list of files that are ppc only:

diff /tmp/ppc.filtered /tmp/x86.filtered | grep -e '<' | awk '{print $2}' | perl -p -e 's/:$//'

The end result should be a list of files that only contain ppc executable mach-o sections. I would suggest verifying the list before nuking anything.

Some notes:

All of the above is done in the Terminal.

This is just a hack; it worked just fine on my system and I'm glad you asked because I wanted to know the same. But it is just a hack.

OTHER TIPS

To find Applications, you can use System Profiler (Called System Information in Lion).

Look under "Software" in the sidebar and choose "Applications"...then wait a long time while it gathers info.

Based on Kevin Ballard's answer, this one works in Mountain Lion:

mdfind -0 'kMDItemContentTypeTree == "public.executable"' | xargs -0 -n 1 sh -c 'lipo="$(lipo -info "$1" 2>/dev/null)"; if [[ "$lipo" == *ppc* && "$lipo" != *i386* && "$lipo" != *x86_64* ]]; then echo "$1"; fi' sh

Also note Rosetta comes with 10.6 - it's just one of the optional installs. Check the DVD that you used to install it with.

In fact, it should ask you to install it when you attempt to launch one of those applications.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top