[CentOS] tar-ing subdirectories separately

Tue Jan 25 00:21:28 UTC 2011
Nico Kadel-Garcia <nkadel at gmail.com>

On Mon, Jan 24, 2011 at 8:00 AM, Leonard den Ottolander
<leonard at den.ottolander.nl> wrote:
> Hello Johan,
>
> On Sun, 2011-01-23 at 14:51 -0600, Johan Martinez wrote:
>> I want to backup a directory using tar, but want separate tarballs for
>> each subdirectory. For example:  # ls dir1
>> subdir1 subdir2 subdir3
>
> Use find(1) for such cases.
>
> $ find <dir> -mindepth 1 -maxdepth 1 -type d -exec tar cz {} -f {}.tgz \;
>
> Regards,
> Leonard.

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. This is particularly common in
Samba mounts of CIFS shares where the share creators cleverly left "$"
on the names of the shares to keep them from being browsed.