Archiving#
This page discusses common linux tools to work with archives. For more infomation check GNU tar
manual.
Create (-cf
)#
The most common way to archive some data is to use tar -cf
command. Here c
refers to “create”, you need specify files to be used for creating of the archive to it. f
refers to file, so you need to specify the path to the output archive file.
The following cell generates some data to be archived and applies long form of the tar -cf
to perform that
[ -d /tmp/archiving ] && rm -r /tmp/archiving
mkdir /tmp/archiving
echo "this is my small test" > /tmp/archiving/test_file
cd /tmp/archiving
tar -c --file=/tmp/archiving/hello.tar test_file
As a result, we got a file with the name we’d specified as the output.
ls -la
total 32
drwxrwxr-x 2 fedor fedor 4096 Feb 23 01:00 .
drwxrwxrwt 23 root root 12288 Feb 23 01:00 ..
-rw-rw-r-- 1 fedor fedor 10240 Feb 23 01:00 hello.tar
-rw-rw-r-- 1 fedor fedor 22 Feb 23 01:00 test_file
Gzip#
Gzip is a typical file compression algorithm. Typical postfix for files is tar.gz
. The tar
utility uses the -z
parameter to indicate that it is working with the gzip algorithm.
The following cell creates a file to be used for the experiment and uses tar -czf
to archive it.
cat /dev/random | head -n 500 > /tmp/some_file
tar -czf /tmp/res.tar.gz /tmp/some_file
tar: Removing leading `/' from member names
The following cell uses tar -xzf
to extract files.
tar -xzf /tmp/res.tar.gz -C /tmp