0

I'm trying to use find to list all installed applications. find /Applications -name "*.app". But this returns a list like:

/Applications/Firefox.app/Contents/MacOS/crashreporter.app
/Applications/Firefox.app/Contents/MacOS/plugin-container.app
/Applications/Firefox.app/Contents/MacOS/updater.app

Using find /Applications -name "*.app" -exec basename {} \; returns a list like:

DVD Player.app
FaceTime.app
Firefox.app

This is better but what I want listed is the application and the directory its stored in: /Applications/Firefox.app

How can I list all installed applications without also listing the subdirectories within the application itself?

I0_ol
  • 1,054
  • 1
  • 14
  • 28

4 Answers4

1

you might try

find /Applications -maxdepth 1 -name "*.app" -type d

Here, -type d limits the search just to directories, while -maxdepth 1 restricts the "recursion level"

ewcz
  • 12,819
  • 1
  • 25
  • 47
  • I thought this might work but `find /Applications -maxdepth 1 -name "*.app" -type d | wc -l` shows only 60 applications installed whereas `find /Applications -name "*.app" -exec basename {} \; | wc -l` shows 200+ applications installed. Even `find /Applications -maxdepth 3 -name "*.app" -type d | wc -l`only shows 96 applications installed. And with `-maxdepth 4` it returns things like `Applications/Firefox.app/Contents/MacOS/crashreporter.app` – I0_ol Sep 07 '16 at 21:23
  • if I understood your question correctly, the command `find /Applications -name "*.app" -exec basename {} \; | wc -l` does something slightly else - it descends to all levels and strips the directory part of the path - for example `find /Applications/Firefox.app -name "*.app" -exec basename {} \;` on my system returns `Firefox.app`, `crashreporter.app`, `plugin-container.app`, `updater.app` - I suppose you are interested just in "Firefox.app" and not the rest? – ewcz Sep 07 '16 at 21:30
  • Ah that explains the much higher number of applications. I didn't realize it was still returning the same `Applications/Firefox.app/Contents/MacOS/crashreporter.app` stripped of its directory. What I'd like is to be able to list the directory as well which you solution does accomplish. But if I had some application hidden 5 levels down this solution wouldn't be able to find it. – I0_ol Sep 07 '16 at 21:38
1

Ask System Profiler

system_profiler SPApplicationsDataType

which gives you more information as just the path, optionally also xml formatted

system_profiler SPApplicationsDataType -xml
vadian
  • 274,689
  • 30
  • 353
  • 361
0

Try

find /Applications -printf "%f\n"|grep "\.app"

with .app in final of name

find /Applications -printf "%f\n"|grep "\.app"
André
  • 19
  • 4
0

This will find all applications, even in subdirectories:

find                  \
      /Applications   \
      -iname "*.app"  \
      -type d         \
| grep  -v  '\.app.*\.app'

-type d means look for directories, since applications are actually directories.

grep -v means filter out matching entries...

matching \.app.*\.app as a regular expression meaning ".app is listed twice"

redolent
  • 4,159
  • 5
  • 37
  • 47