Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Mac OS X > copy directory structure with data place-holders

copy directory structure with data place-holders
Thread Tools
m@
Junior Member
Join Date: Aug 2001
Location: Austria
Status: Offline
Reply With Quote
Aug 21, 2003, 02:21 AM
 
I need a way of sending the directory structure and filenames of a 1.5 Gb directory to a friend, without the actual data! i.e. replace each file by an empty directory of the same name.

/A/B/C.xxx -> /A/B/C/

This way I can just tar.gz up the whole empty directory tree and just send this so he can find his one file (which he doesn't know the name of, contents or location!)

I am sure this is a couple of lines in the shell but I am not that skilled, can any one help me?
m@
     
Senior User
Join Date: Jan 2001
Location: Mahwah, NJ USA
Status: Offline
Reply With Quote
Aug 21, 2003, 07:20 AM
 
Originally posted by m@:
I need a way of sending the directory structure and filenames of a 1.5 Gb directory to a friend, without the actual data! i.e. replace each file by an empty directory of the same name.

/A/B/C.xxx -> /A/B/C/

This way I can just tar.gz up the whole empty directory tree and just send this so he can find his one file (which he doesn't know the name of, contents or location!)

I am sure this is a couple of lines in the shell but I am not that skilled, can any one help me?
If the person knows a text string that is in that file you can do a recursive grep on the directories and files for that string. See man grep for more info.

Otherwise, to answer your question directly do:

cd /to/wherever/it/is/likely/to/be
ls -R > filelist.txt

That will dump a list of all the files and folders recursively to the file filelist.txt

If you want to map all the files in the entire system do:

ls -R / > system_list.txt

See man ls for more spiffy options.

This will not replace the filename with a dir name, what would be the point? It will just list all the directories recursively AND all the filenames within them. The listing will look something like this:

Code:
/A: File1 File2 File3 /A/B: /A/B/C: File4 File5 File6
and so on. In the above example there are no files in dir /A/B, only in /A and /A/B/C.
-DU-...etc...
     
m@  (op)
Junior Member
Join Date: Aug 2001
Location: Austria
Status: Offline
Reply With Quote
Aug 21, 2003, 09:05 AM
 
thanks for the help.

Unfortunately the user is only used to point and click, and would not recognise where his data is without following his well trodden path. (Like finding your way home drunk, you don't really read the road signs, you just recognise the turns!)

Unfortunately the data has not, as far as I can tell, been organised an any logical fashion, and raw data needed is binary and thus cannot be searched for a string. To make matters worse (for me) the directory files are also named in a seemingly random fashion. A dump of ls -R would just lead to more confusion.

I just want to send him a small file which would extract to be his data structure, that he can spend the time searching.

Could the whole directory structure be copied, and the file sizes set 1k or something similar?
m@
     
Senior User
Join Date: Jan 2001
Location: Mahwah, NJ USA
Status: Offline
Reply With Quote
Aug 21, 2003, 09:47 AM
 
Originally posted by m@:
thanks for the help.

Unfortunately the user is only used to point and click, and would not recognise where his data is without following his well trodden path. (Like finding your way home drunk, you don't really read the road signs, you just recognise the turns!)

Unfortunately the data has not, as far as I can tell, been organised an any logical fashion, and raw data needed is binary and thus cannot be searched for a string. To make matters worse (for me) the directory files are also named in a seemingly random fashion. A dump of ls -R would just lead to more confusion.

I just want to send him a small file which would extract to be his data structure, that he can spend the time searching.

Could the whole directory structure be copied, and the file sizes set 1k or something similar?
Ah... now I see what you are asking for. Wierd problem. Why not just let him browse the file system as is?
Did you actually read the manpage for grep? It handles binary files. As long as you know of a string that *might* exist in the file. Most binary files DO have strings in them. Try this on a binary file:

strings filename | less

It would be possible to create a tarball (WinZip can handle those) of the entire suspect filesystem structure and create 0K bytes files with the same names. This would be a tad more difficult. Then he can unpack it locally and browse it.

There is also a command called "tree" but I don't think it comes on a stock Mac OS X system. It is available in Linux and other *nix. There is a command in Mac OS X called "mtree". See man mtree for more details. I haven't used it much but it may be useful.

What you want can probably be done in a single line (or two) of perl. Right now what I am thinking of is basically recursively copy the entire suspect file system then recursively cat nothing to each file (that would make each file in the system 0 bytes) then tar the whole thing up.

How many files are in this system? What is the total size of the suspect file system?

du -sk /path/to/system

will tell you the total size in kilobytes.

ls -R | wc -l

will give you an approximate idea of the number of files. (probably a more elegant way to do that).
-DU-...etc...
     
Mac Enthusiast
Join Date: Jun 2000
Location: New Jersey, USA
Status: Offline
Reply With Quote
Aug 25, 2003, 11:24 PM
 
A Perl script to do this would be pretty simple, though probably more than a one-liner. If I can find a few minutes I'll shoot one out, unless someone beats me to it.

Oh, to count files, I've used this:
Code:
find . | tail +2 | wc -l
Not necessarily more elegant than ls -R, but more exact, as ls puts some excess stuff in that shouldn't be counted. I would love to know if there is a "better" way to do this, but the above is pretty quick and clean....

By the way, is there any reason you want the files to be represented by empty directories, rather than simply empty files?
(Last edited by neilw; Aug 25, 2003 at 11:30 PM. )
     
Mac Enthusiast
Join Date: Jun 2000
Location: New Jersey, USA
Status: Offline
Reply With Quote
Aug 26, 2003, 12:51 AM
 
OK, here's a quick and cheesy way to do it:

Code:
find SRC | perl -ne 'chop; s/^SRC/DEST/; mkdir $_;'
In the above line, replace SRC (both times) with the name of the source directory, and DEST with the name of the new destination directory. Make sure DEST is a new directory that doesn't already exist!!!

This will do exactly as you request, create empty direcories where there originally was a file.
     
m@  (op)
Junior Member
Join Date: Aug 2001
Location: Austria
Status: Offline
Reply With Quote
Aug 26, 2003, 09:20 AM
 
Sorry for not responding sooner, I had another deadline. Just for interest there were 72645 files, making up the 1.5 Gb.

I seam to be having a bit of a problem with the perl script. I ran:
Code:
find ~/Desktop/test | perl -ne 'chop; s/^/Users/me/Desktop/test/Tree/; mkdir $_;'
and got back:

Code:
Bareword found where operator expected at -e line 1, near "s/^/Users/me" syntax error at -e line 1, near "s/^/Users/me" Execution of -e aborted due to compilation errors.
With regards to the real data, would there be a problem with the source directory being a mounted volume in /Volumes/server.institute.com/data , ie with special characters not quotes?

Thanks for all the help, is really appreciated.

Matt
m@
     
Mac Enthusiast
Join Date: Jun 2000
Location: New Jersey, USA
Status: Offline
Reply With Quote
Aug 26, 2003, 10:00 AM
 
My bad, I forgot the directory would have slashes in it (doh!) The quickest and dirtiest solution here (just to get it done already) is to change to a different deliminter for the regex; we'll use a bang (!), which shouldn't show up in the file path anywhere. The new command is:

Code:
find SRC | perl -ne 'chop; s!^SRC!DEST!; mkdir $_;'
With your directories, it'd be

Code:
find ~/Desktop/test | perl -ne 'chop; s!^/Users/me/Desktop/test!Tree!; mkdir $_;'
With regards to the real data, would there be a problem with the source directory being a mounted volume in /Volumes/server.institute.com/data , ie with special characters not quotes?
I'm not sure what "find" will report back with a mounted volume. Try running
Code:
find /Volumes/server.institute.com/data | head
and see what file path is reported back (the first line of output should just be the directory you specified). Whatever that is, use it in the Perl expression. If there are special characters, escape them with a preceding backslash. The dots will actually not cause a problem even if you leave them unescaped; other characters might.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 08:22 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2