2

I am attempting to tar up the contents of a root file system, located at $rootfs. The problem is, when I try to tar -c $rootfs > $dest, the directories between my current directory and the actual file system remain. So instead of etc/fstab, I have fun/rootfs/path/etc/fstab when rootfs=fun/rootfs/path, for every single file.

I know about --strip, but the problem is that $rootfs is a relative-path variable, so I don't know how many directories are between the file system and my current directory. I can't cd for a similar reason; $dest is a relative-path variable and I have to stay in the current directory to create the archive in the proper location.

Is there a way I can ignore the rootfs path when creating the archive?

2 Answers 2

2

You could generate the listing of files relative to the $rootfs path and then use -C $rootfs -T <file-of-filenames> to create the archive. You cannot use a wildcard to generate the list of files on the tar command line as that will not complete correctly. You could use something like find or ls to do it though.

2

I’m not sure I understand the question, but how about

(cd "$rootfs"; tar -c .) > "$dest"

so the tar runs in the $rootfs directory, but $dest is created relative to the current directory.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .