0

I am using tree to list contents of a folder. I have many macOS apps with .app extension. I want tree to list them but ignore the contents inside it. How to do that? Thanks.

1
  • tree is a plain POSIX command so does not know about macOS bundles. You'll need a macOS specific tool.
    – mmmmmm
    Commented Sep 23, 2023 at 13:32

1 Answer 1

1

tree has -P and -I to show/hide files based on wild-card patterns but I didn't have any luck so far using them to hide the content of specific directories.

You can remove the content of NAME.app directories with grep though:

tree -f | grep -v '\.app/'

-f is required in this case to allow filtering on the whole path.

If you don't want to see the whole path, you can also remove it again with sed:

tree -f | grep -v '\.app/' | sed 's| \./.*/||'

The resulting output is similar to the one you get without -f, but without the content of the .app directories.

3
  • Thanks. Works. But I don't want the full path prefix for each file listed. I guess I will just remove the app content entries manually.
    – John Doe
    Commented Sep 23, 2023 at 20:45
  • @JohnDoe Found a way to remove the path after the filtering. Not sure it covers all edge cases.
    – nohillside
    Commented Sep 25, 2023 at 20:11
  • I did not get time to test it. I will update when I do. Thank you!
    – John Doe
    Commented Oct 3, 2023 at 19:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .