Search code examples
macososx-snow-leopard

Find all PPC libraries, binaries and applications in Snow Leopard


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!


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.