create text index of all files on an external drive

Discussion in 'Mac Accessories' started by stefpos007, Nov 28, 2010.

  1. stefpos007 macrumors newbie

    Nov 28, 2010
    Can anybody help me create a txt file of all of the files that reside on an external hard drive? Even including file size, date last modified.

    I have many hard drives and it would be nice to be able to have a txt file that I could open and search for a file name and by doing so know what hard drive the file lives on. I know there is DOS ways to do this on PC's but I don't know how to do it on a mac.

    Any ideas??

  2. dissolve macrumors 6502a

    Aug 23, 2009
    You're looking for the ls command under Unix. For example:

    ls -l ~/Desktop/some_folder
    will print out all files in that folder, permissions, groups, size, date, and some other bits of information. Go to this page for a list of options you can use. It won't take much more effort to write a shell script that'll dump that information into a text file.
  3. dissolve macrumors 6502a

    Aug 23, 2009
    Sorry for the double post, but here's a quick little script that'll output the ls command to a text file. It doesn't respect newlines for some reason, so you'll have to fiddle with it a bit to get something besides a long string of information.

    FILES=$(ls -o /Volumes/SOME_DRIVE)
    echo $FILES > ~/Desktop/files.txt
    The -o doesn't print out group names, but does the same as the -l option. If you want all the info, use -l instead. The location of the drive should be pretty straightforward. The above code will create a txt file (and overwrite one of the same name!!) and dump the output of the ls command into it. You can change this to create the file wherever you'd like (the ~ denotes your Home folder). Hope this gets you started on the right track.

Share This Page