Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Could you please give me an example of using the tree command to filter out result as follows:

  • to ignore directories (say bin, unitTest)
  • only listing certain files having extensions (say .cpp, .c, .hpp, .h)
  • providing full path-names of only the resultant files matching the criteria.
share|improve this question

2 Answers 2

One way is to use patterns with the -I and -P switches:

tree -f -I "bin|unitTest" -P "*.[ch]|*.[ch]pp." your_dir/

The -f prints the full path for each file, and -I excludes the files in the pattern here separated by a vertical bar. The -P switch inlcudes only the files listed in the pattern matching a certain extension.

share|improve this answer

use find and tree command that is use find's prune to exclude directories of search and use tree -P for searching the pattern.

Use the prune switch, for example if you want to exclude the misc directory just add a -path ./misc -prune -oto your find command.

for eg.find . -path ./misc -prune -o -exec tree -P <pattern> {} \; or you can use -name "*.cpp" in find

for excluding multiple directories use

find . -type d \( -path dir1 -o -path dir2 -o -path dir3 \) -prune -o

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.