Get number of files or directory using tree

Tree is an useful linux command to display a tree representation a full directory structure or a part of it.

On a Debian based distro like Ubuntu install:

sudo apt-get install tree

The last line of tree print a line like this:

346 directories, 174 files

If you’re changing files and directories and you want a real-time update of files and directories number, you can use watch.

watch -n 20 'tree | tail -n 1'

Tree will print the tree, tail will extract the last line, then watch will refresh the result every 20 seconds.

Advertisements

Tertiary links / 2: tree workaround

On Tertiary links onĀ Drupal I described a simple approach to display the “tertiary” menu (childrens of secondary menus) on Drupal 5.x. This is an useful but sometimes limiting approach, since the secondary menu disappears when tertiary menu is displayed.

This is an alternative workaround made using a customized menu_tree function:

template.php:

function custom_menu_tree_secondary($pid = 1) {
  $menu = menu_get_menu();
  $output = '';

  if (isset($menu['visible'][$pid]) && $menu['visible'][$pid]['children']) {
    foreach ($menu['visible'][$pid]['children'] as $mid) {
      $type = isset($menu['visible'][$mid]['type'])
? $menu['visible'][$mid]['type'] : NULL;
      $children = isset($menu['visible'][$mid]['children'])
? $menu['visible'][$mid]['children'] : NULL;
      # display only the children menu of the current menu
      if(menu_in_active_trail($mid)) {
      	$output .= theme('menu_tree', $mid);
      }
    }
  }
  return $output;
}

page.tpl.php (in place of standard $secondary block):

<div id="secondary">
<?php if ($secondary_links): ?>
<?php echo tools_menu_tree_secondary(variable_get('menu_primary_menu', 0));?>
<?php endif; ?>
</div>

Tested on:

  • Drupal 5.x
  • Zen subtheme