How to get tree -a to ignore .git directories?

7,047

Solution 1

You need to use the -I flag to exclude a pattern:

tree -a -I '.git'

Hope it helps.

Solution 2

I wrote a node based clone of tree called tree-fiddy that honors gitignore settings. It's pretty alpha right now, but it's working fine on my machines.

Solution 3

I was in the need to exclude .git as well as .vendor and didn't know how to specify multiple directories.

This works:

tree -a -I '.git|.vendor'
Share:
7,047

Related videos on Youtube

Oliver Salzburg
Author by

Oliver Salzburg

Updated on September 18, 2022

Comments

  • Oliver Salzburg
    Oliver Salzburg over 1 year

    I love using tree to list directories, and I have a git repository with all my dotfiles. For me to be able to see them I need to do tree -a, but that will also list the contents inside the .git directory, which most people (myself included) never dare touching.

    How would I get tree -a to exclude only the .git directory?

  • Jon Bentley
    Jon Bentley about 3 years
    For this particular use you can shorten it to tree -aI .git
  • Admin
    Admin about 2 years
    Very interesting, because the intuitive tree -a -I .git -I .vendor is only taking the last one into account.