1
00:00:06,900 --> 00:00:13,065
In this video I will tell you about tar, the
tape archiver. In case you are wondering. Tape archiver, that's a

2
00:00:13,065 --> 00:00:19,230
backup tape that in the past you would connect to
a parallel port on your computer to stream a backup.

3
00:00:20,089 --> 00:00:24,359
Pretty slow, pretty primitive, but hey,
that's the way how it was.

4
00:00:24,879 --> 00:00:28,120
TAR was the utility to
create files on that backup tape.

5
00:00:28,739 --> 00:00:33,274
TAR is still there even if backup
tapes are not used that often anymore. And

6
00:00:33,274 --> 00:00:37,810
the basic use of TAR is to
archive, to extract or to list files.

7
00:00:39,189 --> 00:00:45,364
The basic commands are TAR CVF where C
is for create, V is verbose and F is

8
00:00:45,364 --> 00:00:51,539
followed by the name of the file that
you want to create. Like myarchive TAR home.

9
00:00:52,119 --> 00:00:57,439
What will that do? Well, it
will archive the home directory into the

10
00:00:57,439 --> 00:01:02,759
archive file archive tarot and then
you can use XVF to extract it.

11
00:01:03,539 --> 00:01:08,409
If you are going to extract it, you should
notice that extraction by default happens to the current path.

12
00:01:09,090 --> 00:01:13,609
If that's not what you want, you can
use C to switch to the output path.

13
00:01:14,790 --> 00:01:18,719
Or you can also go into
the output path beforehand because then

14
00:01:18,719 --> 00:01:22,650
it will extract to the
current directory and nothing is happening.

15
00:01:24,219 --> 00:01:29,109
When you have a backup file and you
are wondering what is inside, it might also

16
00:01:29,109 --> 00:01:34,000
be useful to use T VF because
that will show the contents of an archive.

17
00:01:34,819 --> 00:01:41,099
And if ever you are wondering if a file is an archive or
not, you can use the file utility to get more details about a file.

18
00:01:41,939 --> 00:01:46,305
And in case you are wondering why would
I want to do that? Because an archive

19
00:01:46,305 --> 00:01:50,670
has TAR as the extension, isn't it? No,
it's not. The extension is just a convenience.

20
00:01:50,769 --> 00:01:56,533
On the Linux operating system. Linux extensions file have
a so called magic code at the start of

21
00:01:56,533 --> 00:02:02,296
a file that helps the Linux operating system to
identify what type of file it is. And you

22
00:02:02,296 --> 00:02:08,060
can do so manually using file. I have
seen situations where I downloaded something from the Internet.

23
00:02:08,360 --> 00:02:12,250
It didn't have an extension, so
I didn't know what this is. An

24
00:02:12,250 --> 00:02:16,139
archive, an executable. Then the file
utility is really a very convenient utility.

25
00:02:17,460 --> 00:02:24,219
Now back to tar. TAR doesn't compress and
at all. If you want to add compression,

26
00:02:24,219 --> 00:02:30,979
you use z or j or uppercase
j respectively for GZIP, BZIP2 or XZ compression.

27
00:02:31,860 --> 00:02:35,110
Before I show you more, we need
to talk a bit about Unix styles.

28
00:02:35,710 --> 00:02:38,300
TAR supports two
ways to provide arguments.

29
00:02:39,580 --> 00:02:44,300
You can use the options without a
minus in front of them like TAR cvf.

30
00:02:44,879 --> 00:02:47,020
That's what we call
the BSD Unix style.

31
00:02:47,599 --> 00:02:53,590
And there is the option to use the arguments with a
minus in front of them. And that's System 5 Unix style.

32
00:02:54,110 --> 00:02:55,030
Little bit
of background.

33
00:02:55,610 --> 00:03:00,310
In the 1980s, Unix was the leading
operating system and there were two main

34
00:03:00,310 --> 00:03:05,009
dialects in Unix and one dialect was
BSD. The other dialect was System 5.

35
00:03:06,229 --> 00:03:09,030
In the end, System
5 became the dominant dialect.

36
00:03:09,590 --> 00:03:14,460
And that is why some of the
common practices from System 5 still exist nowadays.

37
00:03:14,960 --> 00:03:20,094
But utilities like TAR, but also PS
that have a BSD origin still honor the

38
00:03:20,094 --> 00:03:25,229
BSD origin by allowing you to put
arguments without a minus in front of them.

39
00:03:25,949 --> 00:03:27,509
Let me show you
how to work with tar.

40
00:03:29,330 --> 00:03:35,082
So I'm going to start using TAR
cvf, that's BSD style, you see etc tar

41
00:03:35,082 --> 00:03:40,835
and I'm going to put etc in
there and oh boy, I'm getting exiting with

42
00:03:40,835 --> 00:03:46,587
failure status due to previous errors. You
know what I. I know what the errors

43
00:03:46,587 --> 00:03:52,340
are. The etc directory is not
readable completely for non root users.

44
00:03:52,379 --> 00:03:58,014
So I need to do this
with sudo privileges and then LS

45
00:03:58,014 --> 00:04:03,649
l on etc TAR is
showing that the archive was created.

46
00:04:04,750 --> 00:04:10,026
Now as I mentioned, we can also
apply compression. So let's do the same

47
00:04:10,026 --> 00:04:15,303
command, but this time we put a
Z in there for for gzip compression

48
00:04:15,303 --> 00:04:20,579
and I'm calling the resulting file
etc star gz same etc directory.

49
00:04:21,959 --> 00:04:28,180
And before we are going to compare, I'm
also going to use J for bzip2 compression.

50
00:04:30,399 --> 00:04:36,420
And let's also do that with
XZ compression using the uppercase j option.

51
00:04:38,740 --> 00:04:40,699
Do you notice that
it is really slowing down?

52
00:04:42,680 --> 00:04:46,920
Well, there's a reason for that.
Let's do an LS l on

53
00:04:46,920 --> 00:04:51,160
etc and we can see the
etc archives that have been created.

54
00:04:51,920 --> 00:04:54,959
So originally the etc
tar was quite big.

55
00:04:55,920 --> 00:05:00,680
The gzip file reduces
it to about 25% and

56
00:05:00,680 --> 00:05:05,439
then bzip2 and xz
reduce it even more.

57
00:05:06,240 --> 00:05:12,634
Now if we want to see what is
inside tar t PVF on etc tar, whichever,

58
00:05:12,634 --> 00:05:19,029
no need to specify the uncompression utility when
you want to show what is inside TAR

59
00:05:19,029 --> 00:05:25,424
recognizes that it is a compressed file and
it will show you automatically the files within.

60
00:05:25,425 --> 00:05:31,819
Of course you are allowed to add
the uncompression utility, but it's really not necessary.

61
00:05:32,600 --> 00:05:37,090
Now I'm going to use
xvf etc tar exe and you

62
00:05:37,090 --> 00:05:41,580
know what, I want to
extract it in the tmp directory.

63
00:05:42,230 --> 00:05:46,500
So there we go. And
when I'm listing the TMP directory,

64
00:05:46,500 --> 00:05:50,769
as you can see, the
etc directory has been created.

65
00:05:51,870 --> 00:05:56,830
And if you don't believe that it worked
out all right, well the tree utility is

66
00:05:56,830 --> 00:06:01,790
always a nice way to verify the contents.
And that really looks like an ATC directory.

67
00:06:02,990 --> 00:06:04,970
One more thing,
the file utility.

68
00:06:05,490 --> 00:06:12,300
So if I would use mvetc tar
to just etc I can do that.

69
00:06:12,800 --> 00:06:17,870
And then there is nothing anymore that
on the etc file indicates what it is.

70
00:06:18,810 --> 00:06:22,540
It's marked as just black and
we really don't see it anymore.

71
00:06:23,079 --> 00:06:28,709
But if you use the file utility, the file
utility is telling that this is a POSIX STAR archive.

72
00:06:29,769 --> 00:06:34,574
And if you want to know what
POSIX is, POSIX is an old Unix

73
00:06:34,574 --> 00:06:39,379
standard to guarantee interoperability between the
different flavors of the UNIX operating system.
