Using 'find ... exec tar ' to archive recent files

Grrr - I want to find all files with a modif. date newer than Dec 3 and tar/zip them into one TGZ archive.

$ rm /tmp/blue.tgz
$ touch /tmp/blue.tgz # to create an empty archive to append to??

$ find . -type f -newermt 2005-12-03 -not -iregex '. cache.' -not -regex '\.' -not -empty -exec tar Avzf /tmp/blue.tgz {} \;

The find command finds the files I want (I've verified by replacing exec with print) and should tar-zip-append to add each file to the tgz archive. In fact, however, the blue.tgz file remains empty.

Need another pair of eyeballs - can anyone spot what I'm doing wrong?

thanks - chap

867MHz Powerbook Mac OS X (10.4.3)

867MHz Powerbook, Mac OS X (10.4.2)

Posted on Dec 13, 2005 11:06 AM

Reply
9 replies

Dec 13, 2005 11:42 AM in response to Chap Harrison

My 'tar' manpage says for the "A" flag:
Append the contents of named file, which must itself be a gnutar archive, to the end of the archive (erasing the old end-of-archive block). This has the effect of adding the files contained in the named file to the first archive, rather than adding the second archive as an element of the first.
Does your 'find' find tar archives or normal files? If the latter, I think you want "r" not "A".

Dec 13, 2005 12:05 PM in response to Daniel Macks

Thanks - I had overlooked the '-r' flag, which is what I should be using (I'm archiving regular files, not archives). However, it makes no difference - the .tgz file remains empty!

I'm testing the use of 'zip' instead of 'tar -rz' and it appears to be working, however it's extremely slow (it appears to copy the zip file each time it adds another file to it).

I'll leave the question open - once upon a time I could use 'find...exec tar' to archive selectively without difficulty.

867MHz Powerbook Mac OS X (10.4.3)

Dec 13, 2005 12:39 PM in response to Daniel Macks

I don't think 'touch' creates a valid gzipped file
('touch foo.gz;gzip -d foo.gz' gives me 'gzip:
foo.gz: unexpected end of file'). Also, tar's -r mode
seems to work for non-gzipped tar archives but not
for the compressed ones...fink's tar dumps core and
Apple's (from OS X 10.3) reports '/usr/bin/tar:
Cannot update compressed archives'.


I think you're right - and perhaps I'm not seeing the error messages because 'tar' is being run by 'find'.
- - - - -
I'm not sure about protocol here - the original question is answered, but I still would like to be able to archive & compress selected files from a directory. Should I begin another topic, rename this one, ... or...?

867MHz Powerbook Mac OS X (10.4.3)

Dec 13, 2005 12:53 PM in response to Chap Harrison

Dunno the proper way in the forum...whatever:)

How about doing the archiving on an uncompressed tarfile and then compressing it when you're done adding files to it? How about dumping the output of 'find' to a file and then passing that list of filenames to tar with the -T flag (i.e., create (-c) the archive containing the files instead of adding (-r) the files to an existing empty archive)?

Dec 13, 2005 1:11 PM in response to Daniel Macks

How about dumping the output of
'find' to a file and then passing that list of
filenames to tar with the -T flag (i.e., create (-c)
the archive containing the files instead of adding
(-r) the files to an existing empty archive)?


That should work. Here's what I eventually used:

$ find . -type f -newermt 2005-12-03 -not -iregex '. cache.' -not -regex '\.' -not -empty -print | zip /tmp/purple.zip -@

The man page for 'zip' states that the '-@' flag is not supported under Mac OS X, but it worked for me. Forget about 'tar' entirely!

Thanks for your help,
Chap

867MHz Powerbook Mac OS X (10.4.3)

Dec 13, 2005 1:26 PM in response to Chap Harrison

Glad it's working. I haven't used zip much...never heard of -@ until just now:) I've often seen notes about "not on MacOS" refer to the pre-OS X days, when there was no such thing as the command-line or pipeline/output-redirection. Do be careful that you don't have any files with spaces in their names because find's "-print" uses spaces to separate each filename.

Dec 13, 2005 8:22 PM in response to Daniel Macks

Do be careful that you
don't have any files with spaces in their names
because find's "-print" uses spaces to separate each
filename.


I don't think that's quite correct - when the output of 'find' is to the terminal, the names are separated by newlines. When the output is piped to another command, they seem to be separated by spaces, but somehow the atomicity of each pathname is preserved even if they contain embedded spaces. At any rate, the command ran correctly even though I have tons of pathnames with embedded spaces.

At least in bash, which is my shell.

867MHz Powerbook Mac OS X (10.4.3)

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Using 'find ... exec tar ' to archive recent files

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.