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 no translation for that post!



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

[Solved] MacOS - Determine which files are executables in Terminal

1 Posts
1 Users
0 Likes
1,275 Views
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2678
Topic starter  

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: