Page 1 of 1
Forum

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.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is most likely no translated for the post!





MacOS - Determine w...
 
Share:
Notifications
Clear all

MacOS - Determine which files are executables in Terminal  

  RSS

Hans
 Hans
(@hans)
Prominent Member Admin
Joined: 7 years ago
Posts: 830
August 22, 2019 6:11 AM  

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. 


ReplyQuote
Share: