Re: tar-ing subdirectories separately

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



Hello Nico,

On Mon, 2011-01-24 at 19:21 -0500, Nico Kadel-Garcia wrote:
> On Mon, Jan 24, 2011 at 8:00 AM, Leonard den Ottolander
> > $ find <dir> -mindepth 1 -maxdepth 1 -type d -exec tar cz {} -f {}.tgz \;

> Ahh-ahh-ahh! You forgot some subdirectories, especially generated from
> projects served to Windows systems, may have spaces in their names,
> and you'll want parentheses around those "{}" bits. Without those,
> chaos can ensue.
> 
> And don't get me *started* on what happens if some smart aleck starts
> slipping "$" into directory names.

I don't know what implementation of find you use, but the stock find on
CentOS 4 and 5 does not do any shell expansions, despite what the man
page might suggest. And why should it, find should be perfectly capable
to quote its results before injecting them back into a shell.

See for yourself:
$ mkdir testdir; cd testdir
$ mkdir foo; touch foo/bar; mkdir foo\ bar; mkdir \$PATH; mkdir \ \.\;rm\ \-rf\ foo\;; ls -1
$ find . -mindepth 1 -maxdepth 1 -type d -exec tar cz {} -f {}.tgz \;
$ ls foo

This is not a perl or shell script, it's a command that substitutes its
own results back into a shell. Afacit it does this safely (compare
printquoted.c). No user interaction in the form of the quoting of "{}"
required. If your version of find does I would consider that a bug ;) .

Regards,
Leonard.

-- 
mount -t life -o ro /dev/dna /genetic/research


_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
http://lists.centos.org/mailman/listinfo/centos


[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]
  Powered by Linux