views:

84

answers:

1

Thanks to a nice post at http://murphymac.com/tree-command-for-mac/, I have my long lost linux command tree so I can see the complete directory tree with a single command. I've implemented it via a function in my .bash_profile like this...

function tree {
find ${1:-.} -print | set -e "s;[^/]*/;   ;g"
}

...but what I would like is a version which does not include the hidden files, i.e. the ones that start with dot.

So I would like this output...

$tree Sites
   .DS_Store
   .localized
   images
      apache_pb.gif
      gradient.jpg
      macosxlogo.png
      web_share.gif
   index.html

... to become...

$tree Sites
   images
      apache_pb.gif
      gradient.jpg
      macosxlogo.png
      web_share.gif
   index.html
+2  A: 

Just one little change:

find ${1:-.} ! -name '.*' -print | set -e "s;[^/]*/;   ;g"

The pattern ! -name '.*' causes find not to match any filename (or directory name) that starts with a dot.

David Zaslavsky
Nice. I got stuck on the regex, when the solution was in the find.
dacracot