From owner-freebsd-questions@FreeBSD.ORG Wed Oct 29 21:33:58 2003 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 3246416A4CE for ; Wed, 29 Oct 2003 21:33:58 -0800 (PST) Received: from mta5.adelphia.net (mta5.adelphia.net [68.168.78.187]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4B0AB43FE1 for ; Wed, 29 Oct 2003 21:33:57 -0800 (PST) (envelope-from andi_payn@speedymail.org) Received: from [10.1.0.9] ([68.65.235.109]) by mta5.adelphia.net (InterMail vM.5.01.06.05 201-253-122-130-105-20030824) with ESMTP id <20031030053359.LRGP15638.mta5.adelphia.net@[10.1.0.9]>; Thu, 30 Oct 2003 00:33:59 -0500 From: andi payn To: Xpression In-Reply-To: <001501c39e99$dafacbc0$0801a8c0@bloodlust> References: <001501c39e99$dafacbc0$0801a8c0@bloodlust> Content-Type: text/plain Message-Id: <1067492035.36829.1863.camel@verdammt.falcotronic.net> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.5 Date: Wed, 29 Oct 2003 21:33:55 -0800 Content-Transfer-Encoding: 7bit cc: FreeBSD-questions Subject: Re: tar question... X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Oct 2003 05:33:58 -0000 On Wed, 2003-10-29 at 19:56, Xpression wrote: > Hi list, the question is: can I tar a hole directory without include the > tree ??? I mean when I tar all files in a /dir1/dir2/dir3 path, the tar file > includes me the path too and I want to tar only the filenames in dir3: I'm > using the syntax tar -czf /path/to/store/myfile.tgz > /the/path/where/are/the/files, any clue ???? Thanksssss... I'm not 100% sure I understand exactly what you want, so I'm going to be extra careful; I apologize if it sounds like I'm talking down to you. The short answer is to use relative paths: cd to where you want to start, and tar from there. If that doesn't immediately answer your question, read on. Let's say your directory structure looks like this: dir1 dir2 dir3 file1 file2 dir4 file3 You want a tarball that contains 'dir3', 'dir3/file1', 'dir3/file2', 'dir3/dir4', and 'dir3/dir4/file3', right? If so, do this: # cd /dir1/dir2 # tar czf /path/to/store/myfile.tgz dir3 If you instead want a tarball that contains 'file1', 'file2', 'dir4', and 'dir4/file3', instead do this: # cd /dir1/dir2/dir3 # tar czf /path/to/store/myfile.tgz * You can do this all in one command with the -C parameter, but it's easier to remember cd than how -C works (globbing gets more complicated, -C works differently on different platforms/tars, and there's extra stuff to worry about if you use it together with -T). If you only want 'file1' and 'file2', and not 'dir4' or any of its contents, do this (the 'n' means to not recurse into subdirectories): # cd /dir1/dir2/dir3 # tar czfn /path/to/store/myfile.tgz * If you want 'file1' and 'file2' and 'file3' but not 'dir4', there's no simple way to do this. You'll have to do something like this (the 'h' means to dereference symlinks and store the original file they point to): # pushd `mktemp -dt tar` # ln -s `find /dir1/dir2/dir3/` ./ # tar czfh /path/to/store/myfile.tgz * # rm -rf `pwd` # popd This isn't perfect (it won't work if there are too many files, and if any of the original files are symlinks they'll be dereferenced too--and if you plan to do this more than once you'll be better off writing a script that wraps this stuff up), but it should give you an idea.