Re: Piping find into tar...

2011-05-14 Thread Eitan Adler
>  | while read X; do ; done
> often gets around many of the problems.

But causes way more. I suggest you read
http://www.dwheeler.com/essays/filenames-in-shell.html and
http://www.dwheeler.com/essays/fixing-unix-linux-filenames.html

> --
>
> Walter M. Pawley 
> Wump Research & Company
> 676 River Bend Road, Roseburg, OR 97471
>         541-672-8975
> ___
> freebsd-questions@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
>



-- 
Eitan Adler
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: Piping find into tar...

2011-05-08 Thread Walt Pawley
FWIW:

Many have recommended using "xargs" to pass the generated list
entries into "tar" or some other archiving program. I've often
had trouble processing lists of filenames using "xargs." Most
of the problems revolve around oddball characters in the
filenames, which tend to be created by users using GUIs. While
certainly no panacea, I've found this sequence in bash/sh

 | while read X; do ; done

often gets around many of the problems.
-- 

Walter M. Pawley 
Wump Research & Company
676 River Bend Road, Roseburg, OR 97471
 541-672-8975
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: Piping find into tar...

2011-05-04 Thread Chris Rees
On 4 May 2011 14:25, "Lowell Gilbert" <
freebsd-questions-lo...@be-well.ilk.org> wrote:
>
> kron24  writes:
>
> > Dne 4.5.2011 11:42, Modulok napsal(a):
>  By the way, in reference to the commands above the -j option is for
> >> bzip2, so the extension should be .tbz o_O
> >>
> >> Thanks everyone! I went with the following, because it works regardless
of
> >> space characters in filenames. (Thanks for the correction on the
extenion. It
> >> should indeed be 'tbz' when using the 'j' flag.)
> >>
> >> find -E . -regex '.*\.txt$' -print0 | xargs -0 tar -cjf result.tbz
> >
> > When the amount of files is huge then tar will be invoked twice
> > or more. Thus result.tbz will contain just files from the last
invocation.
>
> Yes, xargs isn't part of the solution for this case unless you use the
> update mode to tar, which will be much slower.  However, tar can read
> the file list from a file, which can be stdin if you want.  The
> equivalent of the above command would be something like:
>
> find -E . -regex '.*\.txt$' -print0 | tar --null -T - -cjf result.tbz
>
> > I consider cpio a better option here.
>
> The old ways still work very well.
>
> But it's worth noting that on FreeBSD these days, cpio(1) and tar(1) are
> both implemented on the same library, so there are very few things that
> one can do but the other cannot.
>

Why on Earth are people still fooling about contorting tar into weird
shapes

The great thing about pax is It's a drop in replacement for cpio that makes
tar archives; It's designed to be used with find!

Chris
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: Piping find into tar...

2011-05-04 Thread Lowell Gilbert
kron24  writes:

> Dne 4.5.2011 11:42, Modulok napsal(a):
 By the way, in reference to the commands above the -j option is for
>> bzip2, so the extension should be .tbz o_O
>>
>> Thanks everyone! I went with the following, because it works regardless of
>> space characters in filenames. (Thanks for the correction on the extenion. It
>> should indeed be 'tbz' when using the 'j' flag.)
>>
>> find -E . -regex '.*\.txt$' -print0 | xargs -0 tar -cjf result.tbz
>
> When the amount of files is huge then tar will be invoked twice
> or more. Thus result.tbz will contain just files from the last invocation.

Yes, xargs isn't part of the solution for this case unless you use the
update mode to tar, which will be much slower.  However, tar can read
the file list from a file, which can be stdin if you want.  The
equivalent of the above command would be something like:

find -E . -regex '.*\.txt$' -print0 | tar --null -T - -cjf result.tbz

> I consider cpio a better option here.

The old ways still work very well.

But it's worth noting that on FreeBSD these days, cpio(1) and tar(1) are
both implemented on the same library, so there are very few things that
one can do but the other cannot.
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: Piping find into tar...

2011-05-04 Thread kron24

Dne 4.5.2011 14:37, b. f. napsal(a):

Dne 4.5.2011 11:42, Modulok napsal(a):

...

find -E . -regex '.*\.txt$' -print0 | xargs -0 tar -cjf result.tbz


When the amount of files is huge then tar will be invoked twice
or more. Thus result.tbz will contain just files from the last invocation.

I consider cpio a better option here.


The use of simple patterns permitted by tar(1) or cpio(1) may be a
good choice in some cases, but we were responding to the OP's wish to
use find(1), which is a bit more flexible.  If there were a large
number of files, one could still use find and tar in many cases by
appending to the archive rather than (re)creating it with each tar
invocation, e.g.:

  find . -type f -name '*.txt' -print0 | xargs -0 tar -rvf archive.tar
; bzip2 archive.tar


Yes, this would work, of course. Anyway, I prefer to use
"find ... | cpio ... | bzip2 ...".

I just disputed Modulok's solution "find ... | xargs tar -cjf ..."
which wouldn't work in some cases.

BR,
Oli
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: Piping find into tar...

2011-05-04 Thread Robert Bonomi
> From owner-freebsd-questi...@freebsd.org  Wed May  4 02:26:32 2011
> Date: Wed, 4 May 2011 01:25:39 -0600
> From: Modulok 
> To: FreeBSD Questions 
> Subject: Piping find into tar...
>
> List,
>
> I've been playing with the find command lately. Is there a way I can pipe 
> the putput list of files from find, into the tar command to create an 
> archive which contains the files which find lists? I tried the following, 
> but it didn't work
> (obviously).
>
> find -E . '.*\.txt$' -print | tar -cjf result.tgz

You're asking 'the wrong question'.  

tar _requires_ the filenames to  be listed as parameters to the command.

There are at least four ways to accomplish this, given the specific 
example you show.
 
1) The simplest: tar -cjf result.tbz .*.txt *.txt
2) in-line substitution: tar -cjf result.tbz `find -E . '.*\.txt$' -print` 
3) using the '-T' option:
 find -E . '.*\.txt$' -print0 | tar -c -j --null -T - -f result.tbz
3) using xargs:  
 find -E . '.*\.txt$' -print0 | xargs tar -rjf result.tar; bzip2 result.tar


Options 1) or 2) will fail 'immediately', if the pattern expands to an 
excessively long set of filenames.




___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: Piping find into tar...

2011-05-04 Thread b. f.
> Dne 4.5.2011 11:42, Modulok napsal(a):
> >>> By the way, in reference to the commands above the -j option is for
> > bzip2, so the extension should be .tbz o_O
> >
> > Thanks everyone! I went with the following, because it works regardless of
> > space characters in filenames. (Thanks for the correction on the extenion. 
> > It
> > should indeed be 'tbz' when using the 'j' flag.)
> >
> > find -E . -regex '.*\.txt$' -print0 | xargs -0 tar -cjf result.tbz
>
> When the amount of files is huge then tar will be invoked twice
> or more. Thus result.tbz will contain just files from the last invocation.
>
> I consider cpio a better option here.

The use of simple patterns permitted by tar(1) or cpio(1) may be a
good choice in some cases, but we were responding to the OP's wish to
use find(1), which is a bit more flexible.  If there were a large
number of files, one could still use find and tar in many cases by
appending to the archive rather than (re)creating it with each tar
invocation, e.g.:

 find . -type f -name '*.txt' -print0 | xargs -0 tar -rvf archive.tar
; bzip2 archive.tar

b.
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: Piping find into tar...

2011-05-04 Thread kron24

Dne 4.5.2011 11:42, Modulok napsal(a):

By the way, in reference to the commands above the -j option is for

bzip2, so the extension should be .tbz o_O

Thanks everyone! I went with the following, because it works regardless of
space characters in filenames. (Thanks for the correction on the extenion. It
should indeed be 'tbz' when using the 'j' flag.)

find -E . -regex '.*\.txt$' -print0 | xargs -0 tar -cjf result.tbz


When the amount of files is huge then tar will be invoked twice
or more. Thus result.tbz will contain just files from the last invocation.

I consider cpio a better option here.

BR
Oli
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: Piping find into tar...

2011-05-04 Thread Chris Rees
On 4 May 2011 10:42, "Modulok"  wrote:
>
> >> By the way, in reference to the commands above the -j option is for
> bzip2, so the extension should be .tbz o_O
>
> Thanks everyone! I went with the following, because it works regardless of
> space characters in filenames. (Thanks for the correction on the extenion.
It
> should indeed be 'tbz' when using the 'j' flag.)
>
> find -E . -regex '.*\.txt$' -print0 | xargs -0 tar -cjf result.tbz
>
> As for pax, I thought tar could create pax archives too, via the --format
pax
> option?

Pax makes tar by default-- It's a great way to make tars with cpio syntax.

>
> Cheers Everyone!
> -Modulok-
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: Piping find into tar...

2011-05-04 Thread b. f.
On 5/4/11, Modulok  wrote:

>
> As for pax, I thought tar could create pax archives too, via the --format
> pax
> option?

Yes, although I haven't tested it thoroughly.  pax(1) should also be
able to create a number of different archive formats via the -x flag.
I prefer tar(1) (bsdtar/libarchive), because it has more features.

b.
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: Piping find into tar...

2011-05-04 Thread Modulok
>> By the way, in reference to the commands above the -j option is for
bzip2, so the extension should be .tbz o_O

Thanks everyone! I went with the following, because it works regardless of
space characters in filenames. (Thanks for the correction on the extenion. It
should indeed be 'tbz' when using the 'j' flag.)

find -E . -regex '.*\.txt$' -print0 | xargs -0 tar -cjf result.tbz

As for pax, I thought tar could create pax archives too, via the --format pax
option?

Cheers Everyone!
-Modulok-
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: Piping find into tar...

2011-05-04 Thread b. f.
On 5/4/11, Chris Rees  wrote:
> On 4 May 2011 08:44, b. f.  wrote:
>>> I've been playing with the find command lately. Is there a way I can pipe
>>> the
>>> putput list of files from find, into the tar command to create an archive
>>> which
>>> contains the files which find lists? I tried the following, but it didn't
>>> work
>>> (obviously).
>>>
>>> find -E . '.*\.txt$' -print | tar -cjf result.tgz
>>
>> You could use something like:
>>
>> find -X . -name '*.txt' | xargs tar -cjf result.tgz
>>
>> or
>>
>> find . -name '*.txt' -print0 | xargs -0 tar -cjf result.tgz
>>
>> b.
>
> How about using pax?
>
> find . -depth -print | pax -wd | gzip > archive.tgz
>
> or
>
> find . -depth -print | pax -wd | bzip2 > archive.tbz
>
>
> By the way, in reference to the commands above the -j option is for
> bzip2, so the extension should be .tbz o_O

True.  I just reproduced what the OP had.  The archive will still use
bzip2 compression, and bsdtar won't have a problem handling it, but
the name will be misleading.

As you wrote, pax(1) is an option, as are cpio(1) and many others...
You should be able to use -z with pax to avoid the extra pipe and
explicit invocation of gzip in the first case.

b.
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: Piping find into tar...

2011-05-04 Thread Chris Rees
On 4 May 2011 08:44, b. f.  wrote:
>> I've been playing with the find command lately. Is there a way I can pipe the
>> putput list of files from find, into the tar command to create an archive 
>> which
>> contains the files which find lists? I tried the following, but it didn't 
>> work
>> (obviously).
>>
>> find -E . '.*\.txt$' -print | tar -cjf result.tgz
>
> You could use something like:
>
> find -X . -name '*.txt' | xargs tar -cjf result.tgz
>
> or
>
> find . -name '*.txt' -print0 | xargs -0 tar -cjf result.tgz
>
> b.

How about using pax?

find . -depth -print | pax -wd | gzip > archive.tgz

or

find . -depth -print | pax -wd | bzip2 > archive.tbz


By the way, in reference to the commands above the -j option is for
bzip2, so the extension should be .tbz o_O

Chris
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: Piping find into tar...

2011-05-04 Thread b. f.
> I've been playing with the find command lately. Is there a way I can pipe the
> putput list of files from find, into the tar command to create an archive 
> which
> contains the files which find lists? I tried the following, but it didn't work
> (obviously).
>
> find -E . '.*\.txt$' -print | tar -cjf result.tgz

You could use something like:

find -X . -name '*.txt' | xargs tar -cjf result.tgz

or

find . -name '*.txt' -print0 | xargs -0 tar -cjf result.tgz

b.
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: Piping find into tar...

2011-05-04 Thread David Demelier

On 04/05/2011 09:25, Modulok wrote:

List,

I've been playing with the find command lately. Is there a way I can pipe the
putput list of files from find, into the tar command to create an archive which
contains the files which find lists? I tried the following, but it didn't work
(obviously).

find -E . '.*\.txt$' -print | tar -cjf result.tgz

Thanks!
-Modulok-
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Hi Modulok,

As Peter said you could try using the xargs command with find. This 
should works as well:


find -E . '.*\.txt$' -print | xargs tar -czf result.tgz
--
David Demelier
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: Piping find into tar...

2011-05-04 Thread Peter Vereshagin
Wake me up when September ends, freebsd-questions!
2011/05/04 01:25:39 -0600 Modulok  => To FreeBSD Questions :
M> find -E . '.*\.txt$' -print | tar -cjf result.tgz

xargs(1)

?

73! Peter pgp: A0E26627 (4A42 6841 2871 5EA7 52AB  12F8 0CE1 4AAC A0E2 6627)
--
http://vereshagin.org
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Piping find into tar...

2011-05-04 Thread Modulok
List,

I've been playing with the find command lately. Is there a way I can pipe the
putput list of files from find, into the tar command to create an archive which
contains the files which find lists? I tried the following, but it didn't work
(obviously).

find -E . '.*\.txt$' -print | tar -cjf result.tgz

Thanks!
-Modulok-
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"