Results 1 to 3 of 3

Thread: command to output a directory tree map

  1. #1
    Join Date
    Dec 2005
    Beans
    4
    Distro
    Ubuntu Breezy 5.10

    Question command to output a directory tree map

    I need to make an output of a directory tree with all its files, something like this

    Code:
    map
    |
    +-- submap
    |     |
    |     +-- file1.ext
    |     +-- file2.ext
    |     +-- file3.ext
    |
    +-- submap
    |
    .
    Is there a quick way to do something like this?

  2. #2
    Join Date
    Nov 2008
    Location
    Indore, India
    Beans
    Hidden!
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: command to output a directory tree map

    this script will help.{this is not my script}

    Code:
    #!/bin/bash
    # tree.sh
    #  Written by Rick Boivie.
    #  Used with permission.
    #  This is a revised and simplified version of a script
    #+ by Jordi Sanfeliu (and patched by Ian Kjos).
    #  This script replaces the earlier version used in
    #+ previous releases of the Advanced Bash Scripting Guide.
    # ==> Comments added by the author of this document.
    search () {
    for dir in `echo *`
    # ==> `echo *` lists all the files in current working directory,
    #+ ==> without line breaks.
    # ==> Similar effect to for dir in *
    # ==> but "dir in `echo *`" will not handle filenames with blanks.
    do
       if [ -d "$dir" ] ; then # ==> If it is a directory (-d)...
       zz=0                     # ==> Temp variable, keeping track of directory level.
       while [ $zz != $1 ]      # Keep track of inner nested loop.
         do
            echo -n "| "        # ==> Display vertical connector symbol,
                                # ==> with 2 spaces & no line feed in order to indent.
            zz=`expr $zz + 1`   # ==> Increment zz.
         done
         if [ -L "$dir" ] ; then # ==> If directory is a symbolic link...
            echo "+---$dir" `ls -l $dir | sed 's/^.*'$dir' //'`
            # ==> Display horiz. connector and list directory name, but...
            # ==> delete date/time part of long listing.
         else
            echo "+---$dir"        # ==> Display horizontal connector symbol...
            # ==> and print directory name.
            numdirs=`expr $numdirs + 1` # ==> Increment directory count.
            if cd "$dir" ; then          # ==> If can move to subdirectory...
              search `expr $1 + 1`       # with recursion ;-)
              # ==> Function calls itself.
              cd ..
            fi
         fi
       fi
    done
    }
    if [ $# != 0 ] ; then
       cd $1 # move to indicated directory.
       #else # stay in current directory
    fi
    echo "Initial directory = `pwd`"
    numdirs=0
    search 0
    echo "Total directories = $numdirs"
    exit 0
    /vikki

  3. #3
    Join Date
    Oct 2007
    Location
    Chennai, India
    Beans
    3,804
    Distro
    Ubuntu Development Release

    Re: command to output a directory tree map

    Quote Originally Posted by TripleSix View Post
    I need to make an output of a directory tree with all its files, something like this
    Is there a quick way to do something like this?
    Code:
    sudo apt-get install tree
    tree
    Cheers,PRShah
    Make your own: Ubuntu, Kubuntu, Xubuntu, Mythbuntu All-in-One Live DVD
    "I never make mistakes; I thought I did, once.. but I was wrong."

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •