[Intro Music]
All right, let's now try 'tar' utility
on practice. And let's create
an archive that will contain all
files and folders located in home
directory for this user. I am
currently inside of this home
directory. And if I list files and
folders here, I should see some
files and a single folder that I
have created over the course of the
previous sections. Now let's create
archive that will contain all
those files and folders. All right,
'tar'; and next, I need to use
option '-c' that will create
new archive create; and next
option will be file, 'f'; it means that
I want to create the archive inside
of the new file; and next will be
name of this file, and let's give
it name, 'archive.tar'; and next
I'll specify which files and
folders I want to put into this tar
file. And let's suppose that I want
to put the entire home directory,
here I could use either '.',
because now I am currently located
in this home directory, or I could
use tilde sign, '~' like so that also
represents home directory for this
particular user. Alright, let's
create archive using such command.
Here I see some informational
messages from tar utility. That
means that it has removed leading
slashes from member names, from
files and folders; and also it
tells me that it has not put into
archive newly created file 'archive
.tar'; and this file was created
actually in home directory first,
and afterwards, those contents of
home directory were placed inside
of this archive. But this archive
itself wasn't placed into itself.
That is the meaning of this
warning. All right, let's know list
files and folders here in home
directory. And now I see newly
created file archive.tar, and
notice its size. Its size is around
400 kilobytes. I could add here
human, 'h' option; and I'll see that the size of
archive.tar file is 380 kilobytes.
Alright, let's now list the
contents of this archive. For that
we could use additional option 't'.
Let's do that. 'tar -t'.
Let's try only this option. And
here will be name of the
archive, archive.tar. I could
use autocomplete, and press
Enter. And now you see that tar
has refused to read archive
contents from terminal. And that
means that without 'f' option, it
will try to read contents from the
terminal, and we have not supplied
any contents inside of the terminal
via STDIN.
That's why we need to add here 'f'
option that will read the contents
from the file. Let me add this
option, '-tf'. And now I see
contents of this archive. It
contains a bunch of other folders
and files that were located in 'root'
folder. 'root' folder is home
directory for 'root' user. All right,
that's our contents of this
archive. Let's again list the files
and folders here. And now let me
demonstrate to you how to create
compressed archive from this
archive. For that we could use
additional utility, 'gzip'. Let's simply
type 'gzip'. And here next, let's
type the name of the file we want
to compress. Actually, you could
compress any file you want, not
necessarily archived file. But
let's compress archive.tar. Press
Enter. And let's list files and
folders now. And now I see here file
'archive.tar.gz', and I don't see
previous file named archive.tar.
And that means that gzip utility
actually replaces file using
compressed file with extension '.gz'.
And notice that size of this
compressed file is much much
smaller than the size of the
tar archive. Recap that size of the
tar archive was 380 kilobytes, and the
size of this archive is just 80
kilobytes. All right, this is how
we were able to compress archive
created using 'tar' command. Also,
it is possible to create a compressed
archive just using single 'tar' command.
Let's do that. Let's remove this
file, 'rm archive.tar.gz'; and now
let's again perform the same action,
compress all files and folders in
the home directory using 'tar' command,
but using additional 'z' option that
will also create compressed
archive. Let's clear terminal and
here will be 'tar'; next let's add
option - first option will be 'c', that
stands for create, create new
archive; next option will be 'z', that
stands for compression, create
compressed archive; and last option
will be file, 'f', create file with
archive; next will be path to
archive, and let's place this file
outside of the home directory for
this user, and I'll place it to one
level up, and the name of the file
will be 'archive.tar.gz'. I am
placing this archive outside of the
home directory for this user,
because now I will actually
compress home directory and I want
to avoid any mistakes. Next will be
path to home directory for this
user, and let's again use tilde, '~'
sign, or I could simply use dot, '.',
here because now I'm currently
located in home directory for this
user. Alright, let's now press
Enter, and see what will happen. And
it seems that now I have not got
any errors, and the file seems to
be created. And in order to view it,
let me go one level up to parent
folder. And the parent folder is
actually 'root' directory. And here
let me list files and folders, 'ls
-l'; and here somewhere at the
top should be this 'archive.tar.gz'
file. And yes, here it is.
This is how we were able to create
a compressed archive using just
single 'tar' command. Alright, now
let me show you how we are able to
extract contents from this archive.
For that we could again use just
single 'tar' command. And let me
create a new folder inside of that
home directory for this user. Let's
'cd' to home directory, and here let's
create a new folder, let's say 'tmp',
and let me 'cd' to this 'tmp' folder;
and here inside of this folder,
I'll use 'tar' command with following
options, 'x', extract. Next, let's add
the option verbose, 'v', that will
actually print the contents of this
archive while extraction will be in
progress. And the next option will
be 'z'. That stands for
uncompressed because we will
uncompress first, and afterwards
extract contents from the
compressed archive. And final
option will be 'f', that stands for
File. Next will be path to archive,
and the let's use here absolute
path, that archive is located in
'root' folder, here will be forward
slash, '/'; and next will be the name of
the archive, let's use tab,
archive.dot.gz. And that's all.
Let's press Enter. And you'll see a
bunch of files that were extracted
into current 'tmp' folder. Let's list
files and folders here. And here I
see actually contents that were
extracted from the archive. This is
how you're able to extract contents
from the compressed archive using
just single 'tar' command. All right,
that's all for compression and
uncompressing. And that is actually
very easy using the 'tar' command.
And the most popular options I have
actually shown you in this lecture.
That's all for this lecture, and
next let's move on, and in the next
one I'll explain to you how to sort
files, and how to sort contents of
files. I will see you next. Bye-Bye.
[no audio]