Initially, tar archives were used to store files conveniently on magnetic tape. The name "Tar" comes from this use; it stands for tape archiver. Despite the utility's name, Tar can direct its output to available devices, files, or other programs (using pipes), it can even access remote devices or files (as archives).
We will be starting with 4 file and 1 dir:
a - aaaaa
b - bbbbb
c - ccccc
d - a dir containing
tar -cvf 1.tar a b c d
Create a new archive with dir to be archived recursively
Specify the archive being used.
Show the files being worked on as tar
is running.
tar -tf 1.tar
List the contents of an archive.
mkdir result
mv 1.tar result/
cd result
tar -xvf 1.tar
ls
Extract files from an archive. You can specify which file/dir you want to extract by giving its name.
tar -xvvf 1.tar
Show extra detail about the files being extracted.
cd ..
rm -r result
ls
tar -cvf 1.tar.gz a b c d
ls (flash the tar.gz)
will auto-detect
|Long|Short|Archive format|
|---|---|---|
|‘--gzip’|‘-z’|gzip
|
|‘--bzip2’|‘-j’|bzip2
|
|‘--xz’|‘-J’|xz
|
|‘--lzip’||lzip
|
|‘--lzma’||lzma
|
|‘--lzop’||lzop
|
|‘--zstd’||zstd
|
|‘--compress’|‘-Z’|compress
|
rm 1.tar.gx
ls
tar -cvf 1.tar a b
tar -cvf 2.tar c d
ls
tar -Af 1.tar 2.tar
ls
tar -tf 1.tar
Append archives to the end of another archive.
tar -df 1.tar
---Nothing
nano c
---lets add a 5 at the end
tar -df 1.tar
---output:
---c: Mod time differs
---c: Size differs
Find differences between archive and file system.
tar -rf 1.tar c
tar -tf 1.tar
---c is at the end! and twice!!!)
Append files to the end of an archive.
tar --delete -f 1.tar c
tar -tf 1.tar
---c are gone
Delete from the archive.
rm 1.tar
tar -cvf 1.tar a b c d
nano b
---lets add the 5
tar -uvf 1.tar a b c d
b
tar -tf 1.tar
will put b at the end
Append files which are newer than the corresponding copy in the archive. Updated files will be tacked to the end of the archive instead of replaced.
https://www.gnu.org/software/tar/manual/tar.html