Want to exclude multiple folders and files when extracting using tar

tar

I would like to extract from a tar file (20G) and exclude many files and folders during the restore. I know how to exclude one or few files/folders but my list is in hundreds which I want to exclude. Unfortunately, they are unique and I can not apply regular expression as well. Is there a way I can put all files and folders names in a file I want to exclude and then use tar.

tar xvfz mvs-2017-06-29-1753.tar.gz -C / *usr/MVS*  --exclude=/usr/MSV/GL

You can see above, I can exclude one folder GL, but if I specify all the other files and folders on the command line, it wont fit. I want to put all my exclude files in a text file and then use in the command argument so that tar can read from the file instead of command line, especially the files I want to exclude.
Please provide some direction.

Best Answer

You should use the --exclude-from=exclude.txt where exclude.txt is your list of files/folders that you want to exclude. The short option is -X and I would recommend you checking the man page: tar(1) man page

Related Question