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.
-
tree is a plain POSIX command so does not know about macOS bundles. You'll need a macOS specific tool.– mmmmmmCommented Sep 23, 2023 at 13:32
1 Answer
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.
-
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 DoeCommented 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 DoeCommented Oct 3, 2023 at 19:36