Delete files or directories from a tar or zip file

The –delete option allows specified files to be completely removed from a tar file (except when the tar file is on magnetic tape). However, this is different from an extraction, as copies of the removed files are not made and placed in the current directory. Thus, for example, the files file1 and file2 can be removed from file.tar with the following:

tar -f file.tar --delete file1 file2

To remove a directory dir1:

tar -f file.tar --delete dir1/*

The -t option tells tar to list the contents of an uncompressed archive without performing an extraction. Thus, the following would list the contents of file.tar:

tar -tf file.tar

2018-02-26T17:07:42+00:00Development, Linux|