Deletes files by filetype from an existing tar archive.
You can use this short tar command.
tar --exclude 'files/**/*.min.*' -cvf --file temp.tar @files.tar && rm files.tar && mv temp.tar files.tar
Or this more verbose tar command.
tar --exclude 'files/**/*.min.*' --create --verbose --file temp.tar @files.tar && rm files.tar && mv temp.tar files.tar
What's heppening here?
We want to remove the minified files (*.min.*
) from files.tar
. Whereas some tar implementations support the --delete
option, for those that don't (Mac OS, for sure), here's how this works:
temp.tar
with the contents of files.tar
, excluding files with a *.min.*
extension.Note: Because we're deleting the original tar file, do ensure to take a backup before you do this.
--exclude
tells tar not to process files or directories that match the specified patternu
or --update
tells tar to add to the archive if the modification time is newer than in the archivev
or --verbose
tells tar to produce verbose outputf
or --file
tells tar that the next parameter will be the tar file to create, extract, append to, list, etc.