Shell command to tar directory excluding certain files/folders

后端 未结 28 2218
春和景丽
春和景丽 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:28

    I had no luck getting tar to exclude a 5 Gigabyte subdirectory a few levels deep. In the end, I just used the unix Zip command. It worked a lot easier for me.

    So for this particular example from the original post
    (tar --exclude='./folder' --exclude='./upload/folder2' -zcvf /backup/filename.tgz . )

    The equivalent would be:

    zip -r /backup/filename.zip . -x upload/folder/**\* upload/folder2/**\*

    (NOTE: Here is the post I originally used that helped me https://superuser.com/questions/312301/unix-zip-directory-but-excluded-specific-subdirectories-and-everything-within-t)

提交回复
热议问题