Compressing Files


Tar

-c     Create a new archive containing the specified items.
-r     Like -c, but new entries are appended to the archive.  Note that this only works on uncompressed archives stored in regular files.  The -f option is required.
-t     List archive contents to stdout.
-u     Like -r, but new entries are added only if they have a modification date newer than the corresponding entry in the archive.  Note that this only works on uncompressed archives stored in regular files.  The -f option is required.
-x     Extract to disk from the archive.  If a file with the same name appears more than once in the archive, each copy will be extracted, with later copies overwriting (replacing) earlier copies.
-T     Filename      In x or t mode, tar will read the list of names to be extracted from filename.  In c mode, tar will read names to be archived from filename.  The special name ``-C'' on a line by itself will cause the current directory to be changed to the directory specified on the following line.  Names are terminated by newlines unless --null is specified.  Note that --null also disables the special handling of lines containing ``-C''.
-v     Produce verbose output.  In create and extract modes, tar will list each file name as it is read from or written to the archive.  In list mode, tar will produce output similar to that of ls(1).  Additional -v options will provide additional detail.

If you want to tar a bunch of files together that are located in different directories, a good option to use is saving all of those absolute/relative paths to a file and then passing in that file to tar all of them together.

# file_list.txt

/Users/samholst/Documents/hi.txt
/Users/samholst/Desktop/myman.txt
/Users/samholst/Projects/project_1/readme.md
tar -czf target_name.tar.gz -T file_list.txt

If you want to extract the tarball

tar -xvf target.tar

Creating a tarball

tar -czf archive_folder_name.tar.gz folder_to_copy

Xdelta3

To retrieve a binary difference using xdelta3, f1.tar is the source, f2.tar is the target file (the one we are comparing the difference with), and f2.xdf is the xdelta file that contains the difference between the two files.

xdelta3 -f -e -s f1.tar f2.tar f2.xdf

To decompress and combine both files if needed, use the following command and the f2.tar will be the most recent version of the file.

xdelta3 -f -d -s f1.tar f2.xdf f2.tar