Shell command to tar directory excluding certain files/folders

后端 未结 28 2199
春和景丽
春和景丽 2020-11-27 08:31

Is there a simple shell command/script that supports excluding certain files/folders from being archived?

I have a directory that need to be archived with a sub dire

28条回答
  •  迷失自我
    2020-11-27 09:32

    Possible redundant answer but since I found it useful, here it is:

    While a FreeBSD root (i.e. using csh) I wanted to copy my whole root filesystem to /mnt but without /usr and (obviously) /mnt. This is what worked (I am at /):

    tar --exclude ./usr --exclude ./mnt --create --file - . (cd /mnt && tar xvd -)
    

    My whole point is that it was necessary (by putting the ./) to specify to tar that the excluded directories where part of the greater directory being copied.

    My €0.02

提交回复
热议问题