Mick writes: > On Sunday 09 January 2011 21:11:02 Alex Schuster wrote: >> Mick writes: >>> I used: >>> tar -X file.list -lcvSf - . | (cd /new_gentoo_partition; tar -xpvf - ) >>> >>> to clone a gentoo / partition to another partition on the same disk (I >>> want to run some tests from it). >>> >>> The file.list has this is in it: >>> >>> tmp/* >>> proc/* >>> sys/* >>> dev/* >>> etc/mtab >>> usr/portage/distfiles/* >> >> Which also excludes /usr/include/sys, not only /sys. And so on. You >> probably have to rewrite this as ./tmp/* , but I did not test this. >> >> And I just learnt that -l is no longer a synonym for --one-file-system, >> at least for tar 1.25. I'd do it with a bind mount this: >> >> mount -o bind / /mnt >> cd /mnt >> tar -cvSf - . | (cd /new_gentoo_partition; tar -xpvf - ) >> >> This way, the original /dev is being copied (including entries console >> and null), without the udev stuff that is mounted on top of /dev, while >> with --one-file-system only the empty /dev directory would be created. > > Thanks Wonko, it seems that I fell victim to my regex ignorance. I started > with /tmp, but that would also exclude the directories and I didn't fancy > creating them manually afterwards. Also dir/* does not include dir/.* > > What shall I use for excluding all the contents of a directory, but not the > directory itself?
Actually it does, although this is wrong in my opinion. But maybe what the user normally intends. I created two directories sys/ and usr/include/sys/, with normal and hidden files: wo...@weird ~/tmp/tar $ ls -a . sys usr/include/sys .: . .. sys usr sys: . .. .hidden visible usr/include/sys: . .. .hidden.h visible.h I tarred them as you did. Note that the hidden file is also excluded, although I did not exclude sys/.*, too: wo...@weird ~/tmp/tar $ tar cf ../foo.tar --exclude='sys/*' . wo...@weird ~/tmp/tar $ tar tf ../foo.tar ./ ./usr/ ./usr/include/ ./usr/include/sys/ ./sys/ As suggested, I added a './' to the exclude file list and tarred the directory. Seems to work: wo...@weird ~/tmp/tar $ tar cf ../foo.tar --exclude='./sys/*' . wo...@weird ~/tmp/tar $ tar tf ../foo.tar ./ ./usr/ ./usr/include/ ./usr/include/sys/ ./usr/include/sys/visible.h ./usr/include/sys/.hidden.h ./sys/ > What shall I use for excluding all the contents of a directory, but > not the directory itself? sed -i 's:^:./:g' file.list Wonko