Can someone explain why this: find . -depth -print0 | cpio --null -pmd /tmp/test will copy all files in and below the current directory -and- this: find . -depth -print | grep -v .iso$ | wc -l will count all the non-iso files -and- this: find . -depth -print | grep .iso$ | wc -l will count *only* the iso files -but- this: find . -depth -print0 | grep -v .iso$ | cpio --null -pmd /tmp/test doesn't copy *anything*? Any suggestions for a work-around would also be most welcome.
On Thu, 22 Jun 2006, Robert wrote:> Can someone explain why this: > find . -depth -print0 | cpio --null -pmd /tmp/test > will copy all files in and below the current directory -and- this: > find . -depth -print | grep -v .iso$ | wc -l > will count all the non-iso files -and- this: > find . -depth -print | grep .iso$ | wc -l > will count *only* the iso files -but- this: > find . -depth -print0 | grep -v .iso$ | cpio --null -pmd /tmp/test > doesn't copy *anything*? Any suggestions for a work-around would also be > most welcome.I think that passing -print0 output to grep is the culprit. How about using find to identify the files rather than grep: find . -depth ! -name '*.iso' -print0 | cpio ... -- Paul Heinlein <heinlein at madboa.com>
Robert wrote:> Can someone explain why this: > find . -depth -print0 | cpio --null -pmd /tmp/test > will copy all files in and below the current directory -and- this: > find . -depth -print | grep -v .iso$ | wc -l > will count all the non-iso files -and- this: > find . -depth -print | grep .iso$ | wc -l > will count *only* the iso files -but- this: > find . -depth -print0 | grep -v .iso$ | cpio --null -pmd /tmp/test > doesn't copy *anything*? Any suggestions for a work-around would also > be most welcome.Because -print0 generates a NULL separated list - so grep will match .iso\0 in the string generated by find and hence not output any list for cpio to read ... One workaround: find . -depth -print | grep -v .iso$ | cpio -pmd /tmp/test James Pearson
On Thu, 2006-06-22 at 07:21 -0500, Robert wrote:> Can someone explain why this: > find . -depth -print0 | cpio --null -pmd /tmp/test > will copy all files in and below the current directory -and- this: > find . -depth -print | grep -v .iso$ | wc -l > will count all the non-iso files -and- this: > find . -depth -print | grep .iso$ | wc -l > will count *only* the iso files -but- this: > find . -depth -print0 | grep -v .iso$ | cpio --null -pmd /tmp/test > doesn't copy *anything*? > Any suggestions for a work-around would also be most welcome.Replace the print0 with print. If you need to know why, redirect your find print0 output to a file & then do an od -c on it. Hint: cpio expects one entry per line (in spite of what it did for you) and grep operates on lines of input. If it's not clear after doing the od -c, call again. :-) BTW, this is not a wise-acre reply. I've always been victimized by the unexpected behavior of the utilities (my fault, not their's... *usually*) and have become somewhat adept at discovery of underlying cause. The method I post above is just sharing my experience. Oh! Also, a vi on the two files (made by print0 and print) will give an indication.> <snip>HTH -- Bill -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part URL: <http://lists.centos.org/pipermail/centos/attachments/20060622/569b7db2/attachment-0002.sig>
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Thu, Jun 22, 2006 at 07:21:22AM -0500, Robert wrote:> Can someone explain why this: > find . -depth -print0 | cpio --null -pmd /tmp/test > will copy all files in and below the current directory -and- this: > find . -depth -print | grep -v .iso$ | wc -l > will count all the non-iso files -and- this: > find . -depth -print | grep .iso$ | wc -l > will count *only* the iso files -but- this: > find . -depth -print0 | grep -v .iso$ | cpio --null -pmd /tmp/test > doesn't copy *anything*?Because the "grep" in the middle will mess up with the "print0/--null" trick. - -- Rodrigo Barbosa "Quid quid Latine dictum sit, altum viditur" "Be excellent to each other ..." - Bill & Ted (Wyld Stallyns) -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQFEmpBrpdyWzQ5b5ckRAnqcAJ90qGty5cYtUCGqWOSi9tsBMHFl/wCePycq Frc4ukIuN1cOQpYt7vnaSnc=QjBz -----END PGP SIGNATURE-----
On Thu, 22 Jun 2006, Robert wrote:> Can someone explain why this: > find . -depth -print0 | cpio --null -pmd /tmp/test > will copy all files in and below the current directory -and- this: > find . -depth -print | grep -v .iso$ | wc -l > will count all the non-iso files -and- this: > find . -depth -print | grep .iso$ | wc -l > will count *only* the iso files -but- this: > find . -depth -print0 | grep -v .iso$ | cpio --null -pmd /tmp/test > doesn't copy *anything*? > Any suggestions for a work-around would also be most welcome. >Never seen print0 before, but on my system it has the effect of putting all the filenames in single line. So grep -v eliminates the one line that it finds leaving nothing to pass to cpio. man find -print True; print the full file name on the standard output, followed by a newline. -print0 True; print the full file name on the standard output, followed by a null character. This allows file names that contain new- lines to be correctly interpreted by programs that process the find output. cpio will understand the output of -print just fine. No need to use print0 ------------------------------------------------------------------------ Jim Wildman, CISSP, RHCE jim at rossberry.com http://www.rossberry.com "Society in every state is a blessing, but Government, even in its best state, is a necessary evil; in its worst state, an intolerable one." Thomas Paine
Robert wrote:> Can someone explain why this: > find . -depth -print0 | cpio --null -pmd /tmp/test > will copy all files in and below the current directory -and- this: > find . -depth -print | grep -v .iso$ | wc -l > will count all the non-iso files -and- this: > find . -depth -print | grep .iso$ | wc -l > will count *only* the iso files -but- this:> find . -depth -print0 | grep -v .iso$ | cpio --null -pmd /tmp/test > doesn't copy *anything*? Any suggestions for a work-around would also > be most welcome.What does this give you? find . -depth -print0 | grep -v .iso$ The print0 option causes all the file names to be on a single line. So when you grep out .ios$ you're losing the whole line. Here's a tar alternative to the other cpio based solutions: # mkdir /tmp/test # tar cf - . --exclude '*.iso' | (cd /tmp/test; tar xvf -)> > _______________________________________________ > CentOS mailing list > CentOS at centos.org > http://lists.centos.org/mailman/listinfo/centos-- Mark Belanger LTX Corporation
On Thu, 22 Jun 2006, William L. Maltby wrote:> On Thu, 2006-06-22 at 07:21 -0500, Robert wrote: >> Can someone explain why this: >> find . -depth -print0 | cpio --null -pmd /tmp/test >> will copy all files in and below the current directory -and- this: >> find . -depth -print | grep -v .iso$ | wc -l >> will count all the non-iso files -and- this: >> find . -depth -print | grep .iso$ | wc -l >> will count *only* the iso files -but- this: >> find . -depth -print0 | grep -v .iso$ | cpio --null -pmd /tmp/test >> doesn't copy *anything*? >> Any suggestions for a work-around would also be most welcome. > > Replace the print0 with print. If you need to know why, redirect your > find print0 output to a file & then do an od -c on it. > > Hint: cpio expects one entry per line (in spite of what it did for you) > and grep operates on lines of input. If it's not clear after doing the > od -c, call again. :-)cpio, like xargs, can accept an argument list terminated by a null character rather than whitespace. That what the OP was doing with the --null switch (aka -0, also possible with xargs). It's very helpful with unpredictable filenames. -- Paul Heinlein <heinlein at madboa.com>
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Thu, Jun 22, 2006 at 07:21:22AM -0500, Robert wrote:> Can someone explain why this: > find . -depth -print0 | cpio --null -pmd /tmp/test > will copy all files in and below the current directory -and- this: > find . -depth -print | grep -v .iso$ | wc -l > will count all the non-iso files -and- this: > find . -depth -print | grep .iso$ | wc -l > will count *only* the iso files -but- this: > find . -depth -print0 | grep -v .iso$ | cpio --null -pmd /tmp/test > doesn't copy *anything*? > Any suggestions for a work-around would also be most welcome.Okey, a new options for you: find . -depth -print0 | grep -vZ .iso$ | cpio --null -pmd /tmp/test From grep manpage: -Z, --null Output a zero byte (the ASCII NUL character) instead of the character that normally follows a file name. For example, grep -lZ outputs a zero byte after each file name instead of the usual newline. This option makes the output unambiguous, even in the presence of file names containing unusual characters like newlines. This option can be used with commands like find -print0, perl -0, sort -z, and xargs -0 to process arbitrary file names, even those that contain newline characters. - -- Rodrigo Barbosa "Quid quid Latine dictum sit, altum viditur" "Be excellent to each other ..." - Bill & Ted (Wyld Stallyns) -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQFEmpPJpdyWzQ5b5ckRApYKAJ0aCs6gnSSKRUImBCNrUIFG9M/dTwCfTfl7 EtyZapkWy5KTjShOYrKEOvk=S7qC -----END PGP SIGNATURE-----
On Thu, 2006-06-22 at 07:21, Robert wrote:> Can someone explain why this: > find . -depth -print0 | cpio --null -pmd /tmp/test > will copy all files in and below the current directory -and- this: > find . -depth -print | grep -v .iso$ | wc -l > will count all the non-iso files -and- this: > find . -depth -print | grep .iso$ | wc -l > will count *only* the iso files -but- this: > find . -depth -print0 | grep -v .iso$ | cpio --null -pmd /tmp/test > doesn't copy *anything*? > Any suggestions for a work-around would also be most welcome.This doesn't have much to do with bash except that you could easily see the answer if you left off the last element of that last pipeline so you could see the output from grep. You are feeding grep one long line with null terminated filenames when it wants things one separate lines. You can let find do the selection: find . -depth ! -name '*.iso' -print0 | cpio ... but I'd probably: rsync -av --exclude '*.iso' . /tmp/test instead. -- Les Mikesell lesmikesell at gmail.com