tar Syntax Help

Giorgos Keramidas keramida at ceid.upatras.gr
Fri Jul 8 10:42:36 GMT 2005

On 2005-07-07 20:20, Drew Tomlinson <drew at mykitchentable.net> wrote:
> I'm trying to copy an entire file system while using an exclude file
> to avoid copying things such as /dev, /proc, etc.  I've read the man
> page and found the -X or --exclude-from tar option.  I've create a
> file called /exclude.list.  It contains lines such as:
> /exclude.list
> /dev
> /proc
> But I can't figure out how to form the correct command line.  I
> basically want to do this:
> tar -cvf - --exclude-from /exclude.list -C / . | tar xpf - -C .

Perhaps not what you're looking for, but you can perform a similar
"exclude" operation on the output of find(1), using one or more grep(1)
patterns and then feed the rest to cpio(1) in 'pass-through' mode:

	# cd /
	# find / | \
	    grep -v '^/dev/.*' | grep -v '^/proc/.*' | \
	    grep -v '^/mnt/.*' | \
	    cpio -p -dmvu /mnt

The most important detail above is that the childen of /dev, /proc and
/mnt are excluded, but not the directories themselves.  This is why I
trim from the output of find '^/dev/.*' but not '^/dev', '^/proc/.*' but
not '^/proc', etc.

- Giorgos

More information about the freebsd-questions mailing list