1 00:00:00,000 --> 00:00:04,600 [Intro Music] 2 00:00:04,680 --> 00:00:07,098 All right, let's now try 'tar' utility 3 00:00:07,098 --> 00:00:09,480 on practice. And let's create 4 00:00:09,480 --> 00:00:11,430 an archive that will contain all 5 00:00:11,460 --> 00:00:13,470 files and folders located in home 6 00:00:13,470 --> 00:00:15,780 directory for this user. I am 7 00:00:15,780 --> 00:00:17,250 currently inside of this home 8 00:00:17,250 --> 00:00:19,320 directory. And if I list files and 9 00:00:19,320 --> 00:00:21,420 folders here, I should see some 10 00:00:21,420 --> 00:00:23,670 files and a single folder that I 11 00:00:23,670 --> 00:00:25,140 have created over the course of the 12 00:00:25,140 --> 00:00:27,600 previous sections. Now let's create 13 00:00:27,630 --> 00:00:29,490 archive that will contain all 14 00:00:29,490 --> 00:00:31,470 those files and folders. All right, 15 00:00:31,620 --> 00:00:34,260 'tar'; and next, I need to use 16 00:00:34,290 --> 00:00:36,810 option '-c' that will create 17 00:00:36,810 --> 00:00:39,000 new archive create; and next 18 00:00:39,000 --> 00:00:41,190 option will be file, 'f'; it means that 19 00:00:41,220 --> 00:00:43,920 I want to create the archive inside 20 00:00:43,920 --> 00:00:46,560 of the new file; and next will be 21 00:00:46,620 --> 00:00:48,600 name of this file, and let's give 22 00:00:48,600 --> 00:00:52,080 it name, 'archive.tar'; and next 23 00:00:52,080 --> 00:00:53,970 I'll specify which files and 24 00:00:53,970 --> 00:00:56,640 folders I want to put into this tar 25 00:00:56,670 --> 00:00:58,770 file. And let's suppose that I want 26 00:00:58,770 --> 00:01:00,900 to put the entire home directory, 27 00:01:01,080 --> 00:01:02,790 here I could use either '.', 28 00:01:02,790 --> 00:01:04,470 because now I am currently located 29 00:01:04,470 --> 00:01:06,599 in this home directory, or I could 30 00:01:06,599 --> 00:01:09,150 use tilde sign, '~' like so that also 31 00:01:09,150 --> 00:01:11,370 represents home directory for this 32 00:01:11,370 --> 00:01:13,680 particular user. Alright, let's 33 00:01:13,680 --> 00:01:15,540 create archive using such command. 34 00:01:15,870 --> 00:01:17,700 Here I see some informational 35 00:01:17,730 --> 00:01:19,830 messages from tar utility. That 36 00:01:19,830 --> 00:01:21,780 means that it has removed leading 37 00:01:21,810 --> 00:01:23,640 slashes from member names, from 38 00:01:23,640 --> 00:01:25,650 files and folders; and also it 39 00:01:25,650 --> 00:01:28,230 tells me that it has not put into 40 00:01:28,230 --> 00:01:30,870 archive newly created file 'archive 41 00:01:30,900 --> 00:01:32,910 .tar'; and this file was created 42 00:01:32,910 --> 00:01:34,620 actually in home directory first, 43 00:01:34,680 --> 00:01:37,140 and afterwards, those contents of 44 00:01:37,140 --> 00:01:39,000 home directory were placed inside 45 00:01:39,000 --> 00:01:41,070 of this archive. But this archive 46 00:01:41,100 --> 00:01:43,320 itself wasn't placed into itself. 47 00:01:43,470 --> 00:01:44,610 That is the meaning of this 48 00:01:44,610 --> 00:01:46,560 warning. All right, let's know list 49 00:01:46,560 --> 00:01:48,210 files and folders here in home 50 00:01:48,210 --> 00:01:50,490 directory. And now I see newly 51 00:01:50,490 --> 00:01:53,100 created file archive.tar, and 52 00:01:53,100 --> 00:01:55,920 notice its size. Its size is around 53 00:01:55,950 --> 00:01:58,710 400 kilobytes. I could add here 54 00:01:58,710 --> 00:02:01,440 human, 'h' option; and I'll see that the size of 55 00:02:01,470 --> 00:02:05,100 archive.tar file is 380 kilobytes. 56 00:02:05,730 --> 00:02:07,410 Alright, let's now list the 57 00:02:07,410 --> 00:02:09,720 contents of this archive. For that 58 00:02:09,750 --> 00:02:11,669 we could use additional option 't'. 59 00:02:11,880 --> 00:02:14,910 Let's do that. 'tar -t'. 60 00:02:14,970 --> 00:02:17,340 Let's try only this option. And 61 00:02:17,340 --> 00:02:18,390 here will be name of the 62 00:02:18,420 --> 00:02:20,280 archive, archive.tar. I could 63 00:02:20,280 --> 00:02:21,780 use autocomplete, and press 64 00:02:21,780 --> 00:02:24,840 Enter. And now you see that tar 65 00:02:24,900 --> 00:02:26,760 has refused to read archive 66 00:02:26,760 --> 00:02:29,010 contents from terminal. And that 67 00:02:29,010 --> 00:02:31,260 means that without 'f' option, it 68 00:02:31,260 --> 00:02:33,120 will try to read contents from the 69 00:02:33,120 --> 00:02:34,830 terminal, and we have not supplied 70 00:02:34,830 --> 00:02:36,360 any contents inside of the terminal 71 00:02:36,390 --> 00:02:37,601 via STDIN. 72 00:02:37,860 --> 00:02:40,320 That's why we need to add here 'f' 73 00:02:40,350 --> 00:02:42,270 option that will read the contents 74 00:02:42,300 --> 00:02:44,940 from the file. Let me add this 75 00:02:44,970 --> 00:02:49,620 option, '-tf'. And now I see 76 00:02:49,620 --> 00:02:52,080 contents of this archive. It 77 00:02:52,080 --> 00:02:54,480 contains a bunch of other folders 78 00:02:54,510 --> 00:02:57,510 and files that were located in 'root' 79 00:02:57,570 --> 00:02:59,580 folder. 'root' folder is home 80 00:02:59,580 --> 00:03:02,610 directory for 'root' user. All right, 81 00:03:02,730 --> 00:03:04,290 that's our contents of this 82 00:03:04,320 --> 00:03:07,050 archive. Let's again list the files 83 00:03:07,050 --> 00:03:08,880 and folders here. And now let me 84 00:03:08,880 --> 00:03:10,830 demonstrate to you how to create 85 00:03:11,250 --> 00:03:13,410 compressed archive from this 86 00:03:13,440 --> 00:03:15,540 archive. For that we could use 87 00:03:15,570 --> 00:03:18,930 additional utility, 'gzip'. Let's simply 88 00:03:18,930 --> 00:03:21,630 type 'gzip'. And here next, let's 89 00:03:21,630 --> 00:03:23,850 type the name of the file we want 90 00:03:23,850 --> 00:03:25,470 to compress. Actually, you could 91 00:03:25,470 --> 00:03:27,690 compress any file you want, not 92 00:03:27,690 --> 00:03:30,150 necessarily archived file. But 93 00:03:30,150 --> 00:03:32,760 let's compress archive.tar. Press 94 00:03:32,760 --> 00:03:35,130 Enter. And let's list files and 95 00:03:35,130 --> 00:03:38,760 folders now. And now I see here file 96 00:03:38,790 --> 00:03:42,420 'archive.tar.gz', and I don't see 97 00:03:42,420 --> 00:03:44,910 previous file named archive.tar. 98 00:03:45,240 --> 00:03:47,370 And that means that gzip utility 99 00:03:47,520 --> 00:03:50,100 actually replaces file using 100 00:03:50,130 --> 00:03:52,980 compressed file with extension '.gz'. 101 00:03:53,520 --> 00:03:55,620 And notice that size of this 102 00:03:55,620 --> 00:03:57,720 compressed file is much much 103 00:03:57,780 --> 00:03:59,520 smaller than the size of the 104 00:03:59,670 --> 00:04:02,130 tar archive. Recap that size of the 105 00:04:02,160 --> 00:04:05,130 tar archive was 380 kilobytes, and the 106 00:04:05,130 --> 00:04:08,340 size of this archive is just 80 107 00:04:08,340 --> 00:04:11,070 kilobytes. All right, this is how 108 00:04:11,070 --> 00:04:13,830 we were able to compress archive 109 00:04:13,830 --> 00:04:16,470 created using 'tar' command. Also, 110 00:04:16,470 --> 00:04:18,240 it is possible to create a compressed 111 00:04:18,269 --> 00:04:20,760 archive just using single 'tar' command. 112 00:04:20,970 --> 00:04:22,950 Let's do that. Let's remove this 113 00:04:22,980 --> 00:04:27,720 file, 'rm archive.tar.gz'; and now 114 00:04:27,720 --> 00:04:29,700 let's again perform the same action, 115 00:04:29,790 --> 00:04:31,470 compress all files and folders in 116 00:04:31,470 --> 00:04:33,480 the home directory using 'tar' command, 117 00:04:33,510 --> 00:04:36,210 but using additional 'z' option that 118 00:04:36,210 --> 00:04:37,950 will also create compressed 119 00:04:37,980 --> 00:04:40,110 archive. Let's clear terminal and 120 00:04:40,110 --> 00:04:42,150 here will be 'tar'; next let's add 121 00:04:42,180 --> 00:04:44,340 option - first option will be 'c', that 122 00:04:44,340 --> 00:04:46,050 stands for create, create new 123 00:04:46,050 --> 00:04:48,630 archive; next option will be 'z', that 124 00:04:48,660 --> 00:04:50,340 stands for compression, create 125 00:04:50,340 --> 00:04:52,500 compressed archive; and last option 126 00:04:52,530 --> 00:04:55,020 will be file, 'f', create file with 127 00:04:55,050 --> 00:04:57,870 archive; next will be path to 128 00:04:57,900 --> 00:05:00,690 archive, and let's place this file 129 00:05:00,720 --> 00:05:02,430 outside of the home directory for 130 00:05:02,430 --> 00:05:04,650 this user, and I'll place it to one 131 00:05:04,650 --> 00:05:06,870 level up, and the name of the file 132 00:05:06,870 --> 00:05:10,320 will be 'archive.tar.gz'. I am 133 00:05:10,320 --> 00:05:12,000 placing this archive outside of the 134 00:05:12,000 --> 00:05:13,410 home directory for this user, 135 00:05:13,500 --> 00:05:14,700 because now I will actually 136 00:05:14,700 --> 00:05:16,650 compress home directory and I want 137 00:05:16,650 --> 00:05:19,230 to avoid any mistakes. Next will be 138 00:05:19,230 --> 00:05:20,970 path to home directory for this 139 00:05:20,970 --> 00:05:22,770 user, and let's again use tilde, '~' 140 00:05:22,770 --> 00:05:25,230 sign, or I could simply use dot, '.', 141 00:05:25,230 --> 00:05:26,850 here because now I'm currently 142 00:05:26,850 --> 00:05:28,890 located in home directory for this 143 00:05:28,890 --> 00:05:30,870 user. Alright, let's now press 144 00:05:30,870 --> 00:05:33,210 Enter, and see what will happen. And 145 00:05:33,210 --> 00:05:34,770 it seems that now I have not got 146 00:05:34,800 --> 00:05:36,660 any errors, and the file seems to 147 00:05:36,660 --> 00:05:39,030 be created. And in order to view it, 148 00:05:39,060 --> 00:05:41,760 let me go one level up to parent 149 00:05:41,760 --> 00:05:43,590 folder. And the parent folder is 150 00:05:43,590 --> 00:05:45,510 actually 'root' directory. And here 151 00:05:45,510 --> 00:05:47,580 let me list files and folders, 'ls 152 00:05:47,580 --> 00:05:49,740 -l'; and here somewhere at the 153 00:05:49,740 --> 00:05:53,022 top should be this 'archive.tar.gz' 154 00:05:53,022 --> 00:05:54,630 file. And yes, here it is. 155 00:05:54,900 --> 00:05:56,790 This is how we were able to create 156 00:05:56,820 --> 00:05:58,860 a compressed archive using just 157 00:05:58,860 --> 00:06:01,950 single 'tar' command. Alright, now 158 00:06:01,950 --> 00:06:03,780 let me show you how we are able to 159 00:06:03,780 --> 00:06:05,730 extract contents from this archive. 160 00:06:06,120 --> 00:06:08,040 For that we could again use just 161 00:06:08,040 --> 00:06:10,590 single 'tar' command. And let me 162 00:06:10,590 --> 00:06:12,930 create a new folder inside of that 163 00:06:12,930 --> 00:06:15,000 home directory for this user. Let's 164 00:06:15,030 --> 00:06:17,220 'cd' to home directory, and here let's 165 00:06:17,220 --> 00:06:20,040 create a new folder, let's say 'tmp', 166 00:06:20,490 --> 00:06:22,800 and let me 'cd' to this 'tmp' folder; 167 00:06:22,830 --> 00:06:24,360 and here inside of this folder, 168 00:06:24,480 --> 00:06:26,760 I'll use 'tar' command with following 169 00:06:26,790 --> 00:06:30,570 options, 'x', extract. Next, let's add 170 00:06:30,630 --> 00:06:32,430 the option verbose, 'v', that will 171 00:06:32,430 --> 00:06:33,990 actually print the contents of this 172 00:06:34,020 --> 00:06:36,240 archive while extraction will be in 173 00:06:36,240 --> 00:06:38,460 progress. And the next option will 174 00:06:38,460 --> 00:06:40,890 be 'z'. That stands for 175 00:06:40,950 --> 00:06:42,870 uncompressed because we will 176 00:06:42,930 --> 00:06:44,730 uncompress first, and afterwards 177 00:06:44,760 --> 00:06:45,900 extract contents from the 178 00:06:45,900 --> 00:06:47,790 compressed archive. And final 179 00:06:47,790 --> 00:06:49,920 option will be 'f', that stands for 180 00:06:49,950 --> 00:06:53,130 File. Next will be path to archive, 181 00:06:53,160 --> 00:06:54,690 and the let's use here absolute 182 00:06:54,690 --> 00:06:57,120 path, that archive is located in 183 00:06:57,150 --> 00:06:59,220 'root' folder, here will be forward 184 00:06:59,220 --> 00:07:00,990 slash, '/'; and next will be the name of 185 00:07:00,990 --> 00:07:02,400 the archive, let's use tab, 186 00:07:02,460 --> 00:07:05,730 archive.dot.gz. And that's all. 187 00:07:05,970 --> 00:07:07,920 Let's press Enter. And you'll see a 188 00:07:07,950 --> 00:07:10,140 bunch of files that were extracted 189 00:07:10,170 --> 00:07:12,900 into current 'tmp' folder. Let's list 190 00:07:12,900 --> 00:07:15,150 files and folders here. And here I 191 00:07:15,150 --> 00:07:16,920 see actually contents that were 192 00:07:16,920 --> 00:07:18,960 extracted from the archive. This is 193 00:07:18,960 --> 00:07:20,670 how you're able to extract contents 194 00:07:20,670 --> 00:07:22,770 from the compressed archive using 195 00:07:22,800 --> 00:07:25,890 just single 'tar' command. All right, 196 00:07:26,070 --> 00:07:27,630 that's all for compression and 197 00:07:27,660 --> 00:07:29,490 uncompressing. And that is actually 198 00:07:29,490 --> 00:07:31,020 very easy using the 'tar' command. 199 00:07:31,320 --> 00:07:32,970 And the most popular options I have 200 00:07:32,970 --> 00:07:34,410 actually shown you in this lecture. 201 00:07:35,040 --> 00:07:36,450 That's all for this lecture, and 202 00:07:36,450 --> 00:07:37,920 next let's move on, and in the next 203 00:07:37,920 --> 00:07:40,290 one I'll explain to you how to sort 204 00:07:40,290 --> 00:07:42,660 files, and how to sort contents of 205 00:07:42,660 --> 00:07:44,760 files. I will see you next. Bye-Bye. 206 00:07:44,760 --> 00:07:47,584 [no audio]