Forrest logo
back to the tree tool

tree:tldr:d6b2a

tree: Print directories within the tree hierarchy, using the wildcard (glob) pattern, and pruning out directories that aren't ancestors of the wanted one.
$ tree -P ${directory_name} --matchdirs --prune
try on your machine

This command is used to display the structure of a directory and its subdirectories as a tree in the terminal window. Here is the breakdown of the options used:

  • tree: It is the main command that generates the directory tree structure.
  • -P ${directory_name}: Specifies a pattern to match directory names against. Only directories that match this pattern will be displayed in the tree structure. ${directory_name} should be replaced with the actual name or pattern of the directories you want to include.
  • --matchdirs: This option ensures that only directories are matched against the pattern specified with -P. Files or other non-directory entities won't be considered.
  • --prune: This option is used to prevent the display of directories that match the pattern but have no subdirectories that also match the pattern. In other words, it prunes directories that don't have any matching subdirectories.

By combining these options, the command will generate a tree structure only for the directories that match the provided pattern, and it will exclude directories that either don't match the pattern or have no matching subdirectories.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the tree tool