Tar extract tar.gz not excluding files from extraction

so I created a tar.gz file under openwrt and amd having issues getting the syntax correct to extract the tar.gz file while excluding/not extracting certain files from the tar.gz. No matter how I format the syntax it either gives and error or extracts the contents I told it to exclude. Sometimes it will even say the specified file I am telling it to exclude (-X) is not inside the tar file when in fact it is. Can someone please clarify the correct syntax for tar to exclude files.

The below code extracts everything inside the archive and ignores my exclude parameter.

tar xzvf /root/compressedfiles.tar.gz -X /root/excludethisfile.sh -C /

What am I missing?



Use the "t" option to see the contents of the file. However, "tar" tends to strip the first "/" when creating the file, you probably want to exclude "root/...".

You can also use --exclude using bsdtar (available as package)

Tar on OpenWrt is probably just a symlink to Busybox, not a full-featured tar.

Yes, it relies on busybox not GNU tar.

From https://linux.die.net/man/1/tar :

-X , --exclude-from = FILE

exclude patterns listed in FILE

tar expects excludethisfile.sh to contain a list of files which should be excluded.

If you want to exclude single files, use --exclude

--exclude = PATTERN

exclude files, given as a PATTERN


Thanks. Thats good to know. I didnt realize that its a file list. I was trying to use the PATTERN value as the FILE to exclude. Thanks for the help.


If your problem is solved, please consider marking this topic as [Solved]. See How to mark a topic as [Solved] for a short how-to.