guh.me - gustavo's personal blog

The Unix 'tree' command is magic

βΈ»

From the tree man page:

Tree is a recursive directory listing program that produces a depth indented listing of files, which is colorized ala dircolors if the LS_COLORS environment variable is set and output is to tty. With no arguments, tree lists the files in the current directory. When directory arguments are given, tree lists all the files and/or directories found in the given directories each in turn. Upon completion of listing all files/directories found, tree returns the total number of files and/or directories listed.

It’s not that useful but it’s easier to use than find (I always forget the flags ;), specially if you need to get the relative path to a file:

tree -P '*\.css' -fi | grep 'css'

It will output something like this:

./src/Recubot/DashboardBundle/Resources/public/css
./src/Recubot/DashboardBundle/Resources/public/css/bootstrap.min.css
./src/Recubot/DashboardBundle/Resources/public/css/buttons.css
./src/Recubot/DashboardBundle/Resources/public/css/layout.css
./src/Recubot/WebsiteBundle/Resources/public/css
./src/Recubot/WebsiteBundle/Resources/public/css/bootstrap.min.css
./src/Recubot/WebsiteBundle/Resources/public/css/layout.css
./vendor/phing/phing/docs/docbook5/en/output/chunkhtml/book.css
./vendor/phing/phing/docs/docbook5/en/output/chunkhtml/highlight.css
./vendor/phing/phing/docs/docbook5/en/output/hlhtml/book.css
./vendor/phing/phing/docs/docbook5/en/output/hlhtml/highlight.css
./vendor/phing/phing/docs/docbook5/en/output/html/book.css
./vendor/phing/phing/docs/docbook5/en/output/html/highlight.css
./vendor/phing/phing/docs/docbook5/en/stylesheets/css
./vendor/phing/phing/docs/docbook5/en/stylesheets/css/book.css
./vendor/phing/phing/docs/docbook5/en/stylesheets/css/book-fancyterm.css
./vendor/phing/phing/docs/docbook5/en/stylesheets/css/highlight.css
./vendor/phing/phing/docs/docbook5/en/stylesheets/css/img
./vendor/sensio/distribution-bundle/Sensio/Bundle/DistributionBundle/Resources/public/webconfigurator/css
./vendor/sensio/distribution-bundle/Sensio/Bundle/DistributionBundle/Resources/public/webconfigurator/css/configurator.css
./vendor/sensio/distribution-bundle/Sensio/Bundle/DistributionBundle/Resources/public/webconfigurator/css/install.css
./vendor/sensio/distribution-bundle/Sensio/Bundle/DistributionBundle/Resources/skeleton/acme-demo-bundle/Acme/DemoBundle/Resources/public/css
./vendor/sensio/distribution-bundle/Sensio/Bundle/DistributionBundle/Resources/skeleton/acme-demo-bundle/Acme/DemoBundle/Resources/public/css/demo.css
./vendor/symfony/assetic-bundle/Tests/Resources/web/stylesheet1.css
./vendor/symfony/assetic-bundle/Tests/Resources/web/stylesheet2.css
./vendor/symfony/assetic-bundle/Tests/TestBundle/Resources/css
./vendor/symfony/assetic-bundle/Tests/TestBundle/Resources/css/bundle.css
./vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Resources/public/css
./vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Resources/public/css/body.css
./vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Resources/public/css/exception.css
./vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Resources/public/css/structure.css

find can do it too, but it returns the absolute path when called with `pwd`, which is not what I want.