views:

45

answers:

3

How can you restrict a node from the command tree?

#1

I need to give a tree of my project files reqularly for my supervisor. These files contain some third-party components which I do not want to show in the tree. I have solved this problem this far by coping the project file to tmp, removing 3rd party-files and then running tree.

However, this procedure is becoming cumbersome. I would like to get a better way to give tree of my files to my supervisor.

#2

I have the files which I want to show in Git so Git may solve this problem. I run unsuccessfully

 git ls-files --with-tree
A: 

You can put the third party tools is a separate subdirectory.

Then you only have to eliminate one node.

Gamecat
A: 

Instead of changing the tree command it might be better to place the 3rd-party files in a sibling folder of, not in a child folder of, your own source.

ChrisW
+1  A: 

You can specify the files you want to match and avoid using general patterns. From the tree manpage:

-P pattern List only those files that match the wild-card pattern. Note: you must use the -a option to also consider those files beginning with a dot '.' for matching. Valid wildcard operators are '*' (any zero or more characters), '?' (any single character), '[...]' (any single character listed between brackets (optional - (dash) for character range may be used: ex: [A-Z]), and '[^...]' (any single character not listed in brackets) and '|' separates alternate patterns.

-I pattern Do not list those files that match the wild-card pattern.

In your specific case, running

tree -I '3rd*'

should hide a directory called '3rd_party', including subdirs and files, while still allowing matches like 'party_3rd'. Obviously, other files and directories not containing '3rd' in the name will also display as normal. I've verified this behaviour with tree v1.5.2.1 on Linux.

ire_and_curses
This does not seem to be enough, since I would like to have a tree of files which match the following `pseudo-code`: **tree ^3rd**. That is match everything else than files or folders starting with 3rd.
Masi
This works for me: tree -I '3rd*'. It doesn't display a dir called "3rd_party", but does display "party_3rd" and other files. Seems to do exactly what you want...
ire_and_curses