Please help the newbie....

I am very new to UNIX, but just playing around with cygwin, I can see that it will work nicely for a project I'm working on. Starting from any given directory, I want my app to spider and collect every filename, size, full path, created date, modified date and last accessed date and save this data in a text file. Yes, this is a server snapshot app to see if changes are made to a production server or if a QA server matches a test server, etc...

I wrote this in VB and although it worked great, it is very slow and if there are more than 100,000 files (which there frequently is) the program will crash or hang.

Can anyone get me started on how write a batch that I can kick off every night and it will do the process noted above and save it to any delimted type file?

I think I can write the batch code if I knew what commands would do what I need here.

Thank you,
Joe

You can write a shell script and add it to the crontab.

I can do the script, but I'm not sure what UNIX commands to use. I need something that will do a directory spider or directory tree. I know you can output almost any UNIX command to a file, so I just need to know which commands will return the filenames, full path, size, created date, last accessed date and modified date.

Thanks,
Joe

I almost have this I think. Just a little bit more knowledge and I will have it. I found this:

find /{starting directory} -type d -ls > snapshot.txt

where {starting directory} is the path where I want to start spidering from. This output some stuff I recognize and some I do not.

19703248369774140 0 drwx------ 2 Administrators ???????? 0 Sep 15 2003 /c:/Documents\

This (above) is a sample line. It imports into Excel real well with Space delimiter.

Now if I can tweak the above line to give me the filenames, and two other date and time stamps. I'm not sure what date is returned here, but I need Created, Modified and Accessed.

I believe the long number is the size in bits? Correct?

By the way, in cygwin, this took about 40 seconds to output over 8000 items. I'm very impressed. UNIX rocks!

Thank you in advance.
Joe

OK, I'm even closer now:

I figured this out on my own:

find /{starting directory} -type f -ls > snapshot.txt

gives me the filenames.

If you could only see the VB source code that I wrote to get the same results as this one UNIX command line. Not to mention how slow VB is. Yikes! That is scary!

Can anyone tell me how to get modified date, created date and last accessed date? Also, is that huge number the file size?

Thanks,
Joe

Yes, the big number in the 5th (or so) field of the ls -l output is the file size. It gives you the modified date. I'm not sure that you can get the created or last accessed date from ls.

Thanks. I'm getting so close. Is there a way to combine the 'find' and the 'stat' commands?

$ find . -type f -exec stat {} \;
  File: `./a'
  Size: 0               Blocks: 0          IO Block: 4096   Regular File
Device: 806h/2054d      Inode: 106085      Links: 1
Access: (0600/-rw-------)  Uid: (  501/zb)   Gid: (  501/zb)
Access: 2005-12-30 09:13:35.000000000 +1100
Modify: 2005-12-30 09:13:35.000000000 +1100
Change: 2005-12-30 09:13:35.000000000 +1100

  File: `./b'
  Size: 0               Blocks: 0          IO Block: 4096   Regular File
Device: 806h/2054d      Inode: 106086      Links: 1
Access: (0600/-rw-------)  Uid: (  501/zb)   Gid: (  501/zb)
Access: 2005-12-30 09:13:35.000000000 +1100
Modify: 2005-12-30 09:13:35.000000000 +1100
Change: 2005-12-30 09:13:35.000000000 +1100

  File: `./c'
  Size: 0               Blocks: 0          IO Block: 4096   Regular File
Device: 806h/2054d      Inode: 106087      Links: 1
Access: (0600/-rw-------)  Uid: (  501/zb)   Gid: (  501/zb)
Access: 2005-12-30 09:13:35.000000000 +1100
Modify: 2005-12-30 09:13:35.000000000 +1100
Change: 2005-12-30 09:13:35.000000000 +1100

Use something like awk to parse this.

Cheers
ZB

I get it to work when I type it exactly the way you have it, but if I do it like this:

find /c: -type f -exec stat {} \;

I get

stat: cannot stat ' <path & filenames> ' : No such file or directory

Cannot anyone explain why?

Thanks,
Joe

Try

find /cygdrive/c -type f -exec stat {} \;