Results 1 to 4 of 4

Thread: Print out directory contents

  1. #1
    Join Date
    Feb 2010
    Beans
    99
    Distro
    Ubuntu 10.04 Lucid Lynx

    Print out directory contents

    Hi all,
    I have a drive with 120 directories, each containing a large number of sub-directories, and a vast number of files. I need a hard copy of this drive's contents for various purposes, i.e. Directory, all files and subdirectories it contains, and all files in the subdirectories, listed in their locations, and was wondering how to go about it, short of copying and pasting everything manually.

    Any suggestions??

  2. #2
    Join Date
    Jan 2008
    Location
    Manchester UK
    Beans
    13,573
    Distro
    Ubuntu

    Re: Print out directory contents

    The -R flag will make ls output subdiectories which you can output to a text file

    Code:
    ls -R /path/to/parent/directory > file.txt
    Now you can open file.txt with gedit or abiword etc and print it

    or just
    Code:
    lpr file.txt

  3. #3
    Join Date
    Nov 2009
    Location
    Australia
    Beans
    57
    Distro
    Ubuntu

    Thumbs down Re: Print out directory contents

    The 'tree' command will give you a few more options for producing a more usable listing.
    You can pipe the output to a file or printer if needed.

    For example to produce a nice indented tree listing use ...
    Code:
    tree -a
    or to produce a simple recursive list of files with full pathnames use ...
    Code:
    tree -fai

  4. #4
    Join Date
    Sep 2006
    Beans
    2,914

    Re: Print out directory contents

    ls -R, tree and find command all can do directory listing. Also, the bash shell

    Code:
    #!/bin/bash
    #bash 4.0
    
    shopt -s globstar
    for file in **/*
    do 
      echo "$file"
    done

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
  •