Listing contents of directory and all sub-directories

vikingshelmut

100% Bull Plop
Ok, I know people will ask "why would you want to do this?"
But I'm curious...

Is there a command I can run that if given a directory name as a starting point, will print a sort of heirarchical (probably spelled that wrong) listing of that directory, and every child directory within? I am interested in finding out:
1. Where installers are installing all their files.
2. Where new files have been added so I can troubleshoot.
3. Just how nerdy I can get.

Anybody have any ideas? I think this would be useful to keep track of any new .kext files installed that I'm not originally aware of (damn I miss labels) without taking screenshots or writing them down by hand.

Idealy I'd like it to have output similar to this:
>do something to "My Pictures"
My Pictures:
beach.jpg
mom.jpg
Vacation:
hawaii.jpg
skiing.jpg
Volcano:
fire.jpg
lava.jpg
zebra.jpg
>

Questions? Answers?
 
You can do this easily from the terminal.

The command is "ls -lR" (those are both "els" and a *capital* "R")

Just navigate to the directory you want to start listing from and type that in - you'll get what you're looking for.

"ls -lR /" will list all files on the machine as it starts from the root directory. If you also want to list *every* file, not just visible ones, add an "a" to the command: "ls -alR"

A couple notes:

1. If you're not familiar with how to navigate in the terminal, type in "ls -lR " (note the space after "R") and then drag the folder you want to get a listing of on top of the terminal window and let go. This will enter the full UNIX path to that directory for you. :)

2. Since the output might be quite extensive, I'd recommend sending the output to a file. To do that: "ls -lR /path/to/directory/if/you/want/ > file.txt" That'll put everything that the command generates into a text file called "file.txt" in your user's home directory.

Hope that helps... and, of course, feel free to ask follow-up questions.

-deraven
 
Thanks deraven, that works great! I tried it out and it outputs perfectly. Since your are so smart, how would I compare two outputs for differences? So if I ran that command on the same directory on two different occassions, what command would I use to compare the two?
Thanks to testuser as well.
 
diff file1 file2

man diff for some options. -q will make it just tell you if they differ, not the details of HOW they differ.
 
Use one of the greatest tools of the Unix world: find. find can do so many great things, and is so useful you'll never understand how you did without it.

There are many many options for this, so I highly recommend reading the man page, but answer your #2 question you'd do:
'find /directory -mtime -2 -print'

That would give you every file modified in the last 2 days under /directory. -3 would be 3 days and etc., if you wanted to find every file older then a time, use a + instead of a -.

For your wanting to do something to the files, there is the -exec option:
'find /directory -mtime -2 -exec cp {} /my/backups/ \; -print

That would find every file in /directory that is less then 2 days old, and copy the file to the directory /my/backups and print out the name of the file as it goes thru.

Brian
 
Thanks vertigo, btoneill...

Btoneill, i tried your method, but it doesnt seem to work. I performed the find command on my documents directory, and it listed two files. I then created a new text file in vi, saved it, and ran the command again, it didn't show up. Then I modified the file via vi, and ran the command again, and it still didn't show up in the list of modified files. Am I doing something wrong??
 
What was the exact command that you ran? I double checked to make sure there wasn't any wackiness with the 'Documents' folder on my home box last night and everything worked fine.
 
Back
Top