From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1PjBnn-0005L5-Bo for garchives@archives.gentoo.org; Sat, 29 Jan 2011 14:29:23 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 7FF82E092B; Sat, 29 Jan 2011 14:28:01 +0000 (UTC) Received: from mx.virtyou.com (mx.virtyou.com [94.23.166.77]) by pigeon.gentoo.org (Postfix) with ESMTP id 3D714E092B for ; Sat, 29 Jan 2011 14:28:01 +0000 (UTC) Received: from weird.localnet (p5794EB7F.dip.t-dialin.net [87.148.235.127]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx.virtyou.com (Postfix) with ESMTPSA id B920139A078 for ; Sat, 29 Jan 2011 15:28:00 +0100 (CET) From: Alex Schuster To: gentoo-user@lists.gentoo.org Subject: Re: [gentoo-user] Cloning a directory hierarchy, but not the content Date: Sat, 29 Jan 2011 15:27:59 +0100 User-Agent: KMail/1.13.5 (Linux/2.6.37-ck; KDE/4.5.5; x86_64; ; ) References: <201101291458.13533.wonko@wonkology.org> <201101291412.p0TECGZV014731@dcnode-02.unlimitedmail.net> In-Reply-To: <201101291412.p0TECGZV014731@dcnode-02.unlimitedmail.net> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-user@lists.gentoo.org Reply-to: gentoo-user@lists.gentoo.org MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201101291527.59925.wonko@wonkology.org> X-Archives-Salt: X-Archives-Hash: a576855ea1c68a6d86ba44eebc023c57 Etaoin Shrdlu writes: > On Sat, 29 Jan 2011 14:58:13 +0100 > > Alex Schuster wrote: > > Hi there! > > > > I am currently putting extra backups to old hard drives I do no longer > > need for other purposes. After that I send the putput out ls -lR and du > > -m to my log directory so I can check what files are on which drive > > without having to attach the drive. > > > > Works, though a better method would be to clone the drive's root > > directory, but with all file sizes being zero. This way I can easily > > navigate the directory structure, instead of browsing through the ls-lR > > file. Is there a utility that does this? It would be even better if the > > files would be created as sparse files, faking the original size. > > > > I just wrote a little script that does this, but it does not do the > > sparse file thing yet, and would have problems with newline in file > > names. And I guess someone already wrote such a utility? > > IIUC, try > > find / -type d -exec sh 'mkdir -p target"$1"' - {} \; Hmm, that does not really seem to work. It tries to execute the whole stuff between single quotes as a command. And I don't really understand what it is supposed to do, shouldn't this be something like mkdir -p /destination/$1/\{\} ? Anyway, this is what I already have. It duplicates the hierarchy with empty files, but I have to add support for sparse files. That won't be too hard, but maybe I'm re-inventing the wheel here. #!/bin/bash src=$1 dst=$2 cd "$src" || exit $? IFS=$'\n' find . | while read file do if [[ -d $file ]] then [[ -d "$dst/$file" ]] || mkdir -p "$dst/$file" elif [[ -f $file ]] then [[ -d "$dst/${file%/*}" ]] || mkdir -p "$dst/${file%/*}" touch "$dst/$file" fi done Wonko