linux: view dir as tree

Perm URL with updates: http://xahlee.info/linux/linux_view_dir_as_tree.html

you can view directory as a tree. It prints a dir in a visual tree format, similar to pstree for processes.

to install:

sudo apt-get install tree

For example, here's a tree view of 〔/etc/X11〕 dir.

linux tree x11 dir screenshot 2013-05-24
screenshot of Linux 「tree」 command.

Tree view is extremely useful, for example:

  • When you are working on a project new to you, you have a directory, with hundreds of files, and you need to get a overview of the structure.
  • You need to organize your files and see each's file size.

Useful Options

Here's some of the most useful options.

  • -L ‹level› → specify depth.
  • -P ‹pattern› → using wildcard to match file names to limit listing. ⁖ *html to show only html files.
  • -d → show dirs only.
  • -r → reverse order.
  • -t → sort output my last modification time.
  • --dirsfirst → list dir before files.
  • --filelimit ‹n› → don't go into dir that's more than ‹n› files.
  • -F → display file type indicator. ⁖ “/” for dir, “*” for executable, etc.
  • -p → show file perm and type and.
  • -h → print file size in human readable format.

See man tree for detail.

Another useful command is du. See: Linux: Show Directory Size: du.

Popular posts from this blog

Browser User Agent Strings 2012

11 Years of Writing About Emacs

does md5 creates more randomness?