Page 1 of 1

MacOS – Determine which files are executables in Terminal

MacOS – Determine which files are executables in Terminal

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
Examples: "MacOS X - Your question", "MS Word - Your Tip or Trick".

Please note that switching to another language when reading a post will not work!
Posts will not have a translated counterpart.

RSS Feed

Home Forums Software MacOS X Software MacOS – Determine which files are executables in Terminal

Viewing 1 post (of 1 total)
  • Author
  • 12381


    I was looking for a way to determine if a file was an executable or not.
    I did find quite a few answers, all seemingly relying on the find command line tool.

    Unfortunately this would not work in a reliable way for me, since find relies on an attribute set to executable, even if this attribute is set for a non-executable file.

    The fix: MacOS comes with a handy little command-line tool “`file`”, which displays file information, for example:

    $> file *
    Distribution: directory
    SomeFile.icns: Mac OS X icon, 3272878 bytes, "ic09" type
    MyPicture.png: PNG image data, 1024 x 1024, 8-bit/color RGBA, non-interlaced
    NSHelpers.pas: Algol 68 source text, ASCII text
    myProgram: Mach-O 64-bit executable x86_64

    As you can see, ‘MyProgram’ is an executable, and nicely indicated as such.
    Since old 32bit executables will have the phrase “executable” in this as well, the following should list all true executable (binaries):

    file * | grep "executable"

    Hope this will be useful to somebody looking for an answer to the same question as well. 

    Note: `file` does not seem to have a function to recurse through subdirectories. 

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.