1 00:00:00,360 --> 00:00:01,290 The beautiful people. 2 00:00:01,290 --> 00:00:07,470 Now, in the last few lectures you've been doing so much stuff with files you've been, you've learned 3 00:00:07,470 --> 00:00:13,230 how to create them, move them around, copy them, delete them, paste them, rename them and search 4 00:00:13,230 --> 00:00:16,320 for them, and so much more, all from the command line. 5 00:00:16,410 --> 00:00:22,650 But even though we can now manipulate files on a grand level, we haven't really seen how to take a 6 00:00:22,650 --> 00:00:27,240 quick peek at what's inside them and manipulate their contents yet. 7 00:00:27,300 --> 00:00:29,880 Well, that's what these next few videos are for. 8 00:00:29,910 --> 00:00:34,500 Over the next few videos, you're going to be learning five new commands that will allow you to manipulate 9 00:00:34,500 --> 00:00:36,240 file contents. 10 00:00:36,480 --> 00:00:41,760 So this is stuff such as reading files, reversing files, and even sticking files together, as well 11 00:00:41,760 --> 00:00:44,120 as reading them in some paging programs. 12 00:00:44,130 --> 00:00:49,710 So what this is going to allow you to do is to get most of your work done from the command line without 13 00:00:49,710 --> 00:00:54,840 ever having to need to open up external editors, which is going to be a massive productivity boost, 14 00:00:54,840 --> 00:01:01,260 and it's going to help you keep you inside the whole command line work process ecosystem. 15 00:01:01,260 --> 00:01:02,560 So this is going to be very, very useful. 16 00:01:02,580 --> 00:01:05,010 It's kind of like a missing piece at the minute. 17 00:01:05,010 --> 00:01:08,370 And after it all, after the end of the next few videos, you're going to be out to perform a whole 18 00:01:08,370 --> 00:01:13,320 bunch of useful functions on the contents of files, which, when combined with what you know about 19 00:01:13,320 --> 00:01:18,450 manipulating files in their entirety, is going to make you the file manipulation master. 20 00:01:18,450 --> 00:01:21,060 So let's just go ahead and jump right into it. 21 00:01:22,320 --> 00:01:22,680 Okay. 22 00:01:22,680 --> 00:01:26,130 So the first command that we're going to take a look at is the cat command. 23 00:01:26,160 --> 00:01:29,460 Now, do you remember those kitten jokes that I was talking to you about earlier? 24 00:01:29,580 --> 00:01:30,990 Well, meow. 25 00:01:31,860 --> 00:01:34,920 So now you've actually seen the cat command before. 26 00:01:35,190 --> 00:01:37,650 So this will be a rather nice refresher. 27 00:01:37,770 --> 00:01:37,880 Okay. 28 00:01:37,890 --> 00:01:41,280 So you can see here on our desktop, we've got a few files. 29 00:01:41,280 --> 00:01:46,290 We've got far one file two, file three, file four and file five dot txt. 30 00:01:46,320 --> 00:01:49,080 So let's take a look at what's inside the first file. 31 00:01:49,080 --> 00:01:53,040 But instead of opening it, we're going to look in our terminal to see what's inside the file. 32 00:01:53,160 --> 00:01:53,490 Okay. 33 00:01:53,500 --> 00:01:56,370 So if we type cat and then file. 34 00:01:56,370 --> 00:01:57,750 Oh, I need to be on the desktop, don't I? 35 00:01:57,780 --> 00:01:59,640 So let me change the desktop. 36 00:01:59,820 --> 00:02:04,920 I click the screen and then type cat and file one dot txt. 37 00:02:05,220 --> 00:02:06,300 I'm going to press enter. 38 00:02:06,480 --> 00:02:11,400 We'll see that the contents of the file have been written to standard output and we can see that the 39 00:02:11,400 --> 00:02:13,980 file contains the word hello. 40 00:02:14,010 --> 00:02:18,420 Now if I press if I double click that and open that graphically, we can see that. 41 00:02:18,420 --> 00:02:18,750 Yes. 42 00:02:18,750 --> 00:02:21,250 All that file contains is the word hello. 43 00:02:21,270 --> 00:02:21,540 Okay. 44 00:02:21,540 --> 00:02:27,720 So using the cat command, we managed to get that the contents of the file printed to standard output. 45 00:02:29,110 --> 00:02:29,500 Okay. 46 00:02:29,500 --> 00:02:31,810 So let's try and see what's in file number two. 47 00:02:31,930 --> 00:02:32,250 Okay. 48 00:02:32,260 --> 00:02:38,620 So if we do that file to txt, we can see the word there is inside. 49 00:02:39,250 --> 00:02:39,790 Hmm. 50 00:02:39,790 --> 00:02:41,910 I guess I guess you can imagine where this is going. 51 00:02:41,920 --> 00:02:42,270 Right. 52 00:02:42,280 --> 00:02:46,660 So if I go file three, it says you file. 53 00:02:46,670 --> 00:02:48,040 I see file four. 54 00:02:48,370 --> 00:02:49,630 It says beautiful. 55 00:02:49,960 --> 00:02:52,720 And I bet we can all guess what's in file number five. 56 00:02:53,110 --> 00:02:55,480 So if I press five, it says people. 57 00:02:55,510 --> 00:03:00,810 Okay, so if you put all the five files together, it says hello there, you beautiful people. 58 00:03:00,820 --> 00:03:01,960 Well, what a coincidence. 59 00:03:01,960 --> 00:03:03,130 I wonder how that happened. 60 00:03:03,430 --> 00:03:07,530 So, in fact, you can actually use the cat command to stick files together. 61 00:03:07,810 --> 00:03:09,910 And that's actually usually what it's for. 62 00:03:09,940 --> 00:03:15,070 Cat is short for the word concatenate, which is a fancy word for stick together. 63 00:03:15,550 --> 00:03:21,340 So what cat does is stick together all of the input files and then pass that that stick together stuff 64 00:03:21,370 --> 00:03:22,630 to standard output. 65 00:03:22,690 --> 00:03:22,860 Okay. 66 00:03:22,870 --> 00:03:29,290 So if we do, if I click the screen, if we do cat file one txt file to txt file three point text file 67 00:03:29,290 --> 00:03:34,030 for txt and file five dot txt and press enter. 68 00:03:34,060 --> 00:03:34,840 You can see that. 69 00:03:34,840 --> 00:03:40,270 Hello there you beautiful people has been made by sticking together the five different files and then 70 00:03:40,270 --> 00:03:43,050 that has been printed to our standard output. 71 00:03:43,060 --> 00:03:49,990 But we can of course redirect this to a new file called Beautiful txt on our desktop, which we see 72 00:03:49,990 --> 00:03:51,070 has been created here. 73 00:03:51,070 --> 00:03:56,560 And when we open that, we now see that we've got a new file that says Hello, are you beautiful people 74 00:03:57,220 --> 00:04:00,970 that has been created by sticking together five other files. 75 00:04:01,060 --> 00:04:04,600 Now we can actually you can see this command line here is quite long, right? 76 00:04:04,600 --> 00:04:07,750 Well, we can actually simplify that using our knowledge of wild cards. 77 00:04:07,750 --> 00:04:15,010 So instead of having cat file 1.2, see file 2.2 key file three point text file 4.2 and 55. txt. 78 00:04:15,040 --> 00:04:22,900 You can just use a wild card like this cat together files 1 to 5 dot txt into beautiful. 79 00:04:22,900 --> 00:04:28,630 So if I if I delete beautiful that text and run that wild card and it's been created again and we can 80 00:04:28,630 --> 00:04:31,440 see here that yep we get exactly the same result. 81 00:04:31,450 --> 00:04:34,870 Hello there, you beautiful people, but a lot less typing. 82 00:04:34,870 --> 00:04:36,130 So that's pretty cool. 83 00:04:36,130 --> 00:04:39,460 Right now the cat command, when you want to stick files together like this, it's useful for sticking 84 00:04:39,490 --> 00:04:44,890 together text files, obviously, but it can be very useful when working with audio or MP3 files, for 85 00:04:44,890 --> 00:04:45,460 example. 86 00:04:45,460 --> 00:04:51,340 So you could have multiple different single MP3 files, you know, different songs, for example, but 87 00:04:51,340 --> 00:04:55,900 you can actually concatenate them together, stick these different files together to create one long 88 00:04:55,900 --> 00:04:57,880 file that has all the music in it. 89 00:04:57,880 --> 00:04:59,080 So that's pretty epic. 90 00:04:59,200 --> 00:05:04,780 So the cat command is used to stick files together, or actually if you want, just read the contents 91 00:05:04,780 --> 00:05:05,890 of a file so we could just do. 92 00:05:05,920 --> 00:05:08,770 Cat beautiful txt so. 93 00:05:08,770 --> 00:05:13,990 Cat beautiful txt and we can see the contents of any of any file which is really, really useful. 94 00:05:13,990 --> 00:05:17,020 But another command that I want to take a look at is the tac command. 95 00:05:17,020 --> 00:05:19,570 So let me just clear the screen here. 96 00:05:19,570 --> 00:05:26,230 So the tac command is just cat spelled backwards and it's used to reverse whatever it receives as an 97 00:05:26,230 --> 00:05:26,710 input. 98 00:05:26,710 --> 00:05:35,800 So if we make a file called Alpha txt by echoing let's say ABC to Alpha txt and we're going to also 99 00:05:35,800 --> 00:05:41,860 echo d e f to alpha and notice the way that we've got two arrows here because we're going to append 100 00:05:41,860 --> 00:05:44,050 to the same file rather than overwrite it. 101 00:05:44,080 --> 00:05:44,470 Okay. 102 00:05:44,980 --> 00:05:50,230 So now if I look in alpha txt we've got ABC on one line and def on another. 103 00:05:50,500 --> 00:05:59,130 So if we read the file, we read the file using cat we sue cat alpha txt we get abc then d e f okay, 104 00:05:59,230 --> 00:06:01,840 but let's see what happens if we read it using tac. 105 00:06:01,840 --> 00:06:06,550 So instead of cat, we read it using tac, which is the cat spelled backwards. 106 00:06:06,760 --> 00:06:10,630 And you see now that we get def then ABC. 107 00:06:10,840 --> 00:06:17,110 So you can see that the tac command actually reads the whole file in reverse but leaves the file the 108 00:06:17,110 --> 00:06:18,220 lines the same. 109 00:06:18,220 --> 00:06:22,960 So it just wrote the last line first and then the first line last. 110 00:06:22,960 --> 00:06:23,200 Right? 111 00:06:23,200 --> 00:06:26,440 But it didn't affect any text on each line. 112 00:06:27,100 --> 00:06:34,090 So if we stick together the various different files here, the file 1 to 5 using cat. 113 00:06:34,090 --> 00:06:40,090 So if we do file 1 to 5 dot txt, you see that we get the output there. 114 00:06:40,090 --> 00:06:44,440 But now I want you to think what might happen if we pipe that into TAC? 115 00:06:45,010 --> 00:06:49,210 Now TAC will reverse the file line wise. 116 00:06:49,210 --> 00:06:55,360 So the last line will be printed first and the first line will be printed last. 117 00:06:55,360 --> 00:06:57,910 So what do you think might come out of this? 118 00:06:57,910 --> 00:06:58,750 Just take a couple of seconds. 119 00:06:58,750 --> 00:06:59,770 Ever think about it? 120 00:07:02,420 --> 00:07:08,450 So what might happen is the last line, which is people would come first and the first line would come 121 00:07:08,450 --> 00:07:08,720 last. 122 00:07:08,720 --> 00:07:11,870 So what might come out is people beautiful? 123 00:07:11,870 --> 00:07:12,940 You there? 124 00:07:12,950 --> 00:07:13,670 Hello? 125 00:07:13,790 --> 00:07:14,720 Okay, so let's have a look. 126 00:07:15,230 --> 00:07:15,560 There we go. 127 00:07:15,560 --> 00:07:17,150 Yeah, people beautiful. 128 00:07:17,150 --> 00:07:18,110 You there? 129 00:07:18,110 --> 00:07:18,650 Hello. 130 00:07:18,650 --> 00:07:23,390 So think of the tag command as reversing a file vertically. 131 00:07:23,390 --> 00:07:26,000 Okay, so it just flips it upside down. 132 00:07:26,000 --> 00:07:29,420 It doesn't affect any of the lines, it just flips it upside down. 133 00:07:29,420 --> 00:07:33,980 And of course, because this is all being printed, the standard output, you can of course redirect 134 00:07:33,980 --> 00:07:36,830 it into another file called reversed tcd and here we are. 135 00:07:36,830 --> 00:07:38,180 Here is reverse text. 136 00:07:38,210 --> 00:07:43,310 When we open that, we see that we've saved the output in that file. 137 00:07:43,310 --> 00:07:48,470 So that one good thing about the tac command where it can be used is again, if we take the example 138 00:07:48,470 --> 00:07:53,090 of MP three files, I don't know if you've ever seen those videos online where people say, Oh, look 139 00:07:53,090 --> 00:07:55,160 what this song says when it's played backwards. 140 00:07:55,160 --> 00:07:58,130 And like, you know, they tried to say it's got some hidden messages in the file. 141 00:07:58,130 --> 00:07:59,570 Maybe you've seen those kind of videos. 142 00:07:59,570 --> 00:08:05,840 Well, maybe they were made using the tag command because if you run an MP three file through through 143 00:08:05,840 --> 00:08:12,350 the command commands, if I did something like tack my file the MP three and save that into another 144 00:08:12,350 --> 00:08:21,110 my reversed file dot MP three then this file, this one here will be the same song but played backwards. 145 00:08:21,410 --> 00:08:24,860 So that's something to to potentially give a go if, if, if you would like. 146 00:08:24,980 --> 00:08:26,630 Okay, so that's the tac command. 147 00:08:26,630 --> 00:08:29,720 The tac command will reverse files vertically. 148 00:08:29,720 --> 00:08:33,530 There's one other that I want to look at, which is called the Rev Command. 149 00:08:33,620 --> 00:08:38,150 So the Rev Command allows you to reverse the content on each line. 150 00:08:38,150 --> 00:08:43,580 So if I clear the screen and we cut together the various different files, again we get hello there, 151 00:08:43,580 --> 00:08:44,510 you beautiful people. 152 00:08:44,510 --> 00:08:49,670 But if I pipe that into the rev command, look what happens here. 153 00:08:51,020 --> 00:08:55,280 It's still saying if you can read it, it still says hello there, you beautiful people. 154 00:08:55,280 --> 00:09:00,140 So the lines are vertically the same, but horizontally they've been reversed. 155 00:09:00,140 --> 00:09:02,450 So the last letter of each line. 156 00:09:02,450 --> 00:09:09,560 So here's the o has is now become the first letter and you know it's reversed them along the lines but 157 00:09:09,560 --> 00:09:12,890 the order of each line is the same, if that makes sense. 158 00:09:12,890 --> 00:09:19,010 If we if we put the the tac command, you can see that people is the first line, whereas here people 159 00:09:19,010 --> 00:09:20,030 is the last line. 160 00:09:20,030 --> 00:09:21,800 But the letters have been reversed. 161 00:09:22,220 --> 00:09:24,740 So this is the way you can think of rev and tack. 162 00:09:24,740 --> 00:09:31,250 Tack reverses a file vertically and rev reverses a file horizontally. 163 00:09:31,550 --> 00:09:32,120 Okay. 164 00:09:32,120 --> 00:09:35,450 Now you can really jumble up files by piping it through both of them. 165 00:09:35,450 --> 00:09:38,990 So if I pipe it through tack, it's going to reverse vertically. 166 00:09:39,410 --> 00:09:47,870 But then if I pipe that also through rev, you've now got a vertically reversed and horizontally reversed 167 00:09:48,290 --> 00:09:52,190 file, which is a good way of jumbling up stuff if you ever find that particularly useful. 168 00:09:52,190 --> 00:09:58,730 But yeah, just to make it easier, just think of tack as reversing files vertically in columns and 169 00:09:58,730 --> 00:10:03,710 you can think of Rev as reversing files horizontally across the rows. 170 00:10:03,710 --> 00:10:10,640 So all of these commands, whether it be cat or it be tack or it be rev, all they're doing is they 171 00:10:10,640 --> 00:10:17,330 are taking a file and reading it into standard input, doing some processing and then, you know, just 172 00:10:17,510 --> 00:10:20,690 spitting that the output to standard output. 173 00:10:20,720 --> 00:10:20,860 Okay. 174 00:10:20,930 --> 00:10:21,920 So they're a good way. 175 00:10:21,920 --> 00:10:26,720 Well, cat is a good way of reading files and you know, the others are a good way of jumbling up stuff. 176 00:10:26,720 --> 00:10:32,630 But the problem is when you read files to the terminal like this, if a file is particularly long, 177 00:10:32,660 --> 00:10:37,370 it can really just clog up your screen and it's not very useful and you find yourself scrolling a long, 178 00:10:37,370 --> 00:10:37,730 long way. 179 00:10:37,730 --> 00:10:44,570 So if we try to find a file that's quite large, so if we say, for example, let's use the find command, 180 00:10:44,900 --> 00:10:48,050 let's search our system up to, let's say a maximum depth of four. 181 00:10:48,050 --> 00:10:52,190 We don't need to go too far for any configuration file. 182 00:10:52,190 --> 00:11:01,310 So a name that ends in com and a size that let's say over 20 kilobytes so we are we only get we only 183 00:11:01,310 --> 00:11:02,420 get two really. 184 00:11:02,630 --> 00:11:05,350 But there's one here in called cups browser. 185 00:11:06,320 --> 00:11:11,600 And this is to do with like printing services and it's apparently a, it's a rather large file. 186 00:11:11,600 --> 00:11:16,580 So if I copy it, copy that and try to cut it out. 187 00:11:16,610 --> 00:11:17,110 Okay. 188 00:11:17,390 --> 00:11:20,630 So if I try to cap that, oops, you see, you see it just happen right there. 189 00:11:20,630 --> 00:11:27,110 If I tried to cap that out and press enter, you see that we've just shut down a stupid amount of lines. 190 00:11:27,110 --> 00:11:27,560 Can you see? 191 00:11:27,560 --> 00:11:31,640 Now, if I wanted to have a look at it, I ended up scrolling all the way through here. 192 00:11:31,640 --> 00:11:32,870 It's not very good, right? 193 00:11:34,160 --> 00:11:37,250 So that's a problem when you're dealing with stuff on the command line. 194 00:11:37,250 --> 00:11:41,600 And we want a more elegant solution to dealing with relatively large files. 195 00:11:41,600 --> 00:11:46,010 And sometimes, you know, if I if I just wanted to read out of how maybe I don't want all of the file, 196 00:11:46,010 --> 00:11:48,380 maybe I only want a certain snippet of it. 197 00:11:48,380 --> 00:11:52,220 Maybe I only want the top ten lines or the bottom ten lines or something like that. 198 00:11:52,220 --> 00:11:57,650 And we need to have a better way of being able to deal with file contents on the command line. 199 00:11:57,650 --> 00:12:00,470 So in summary, so that's what we're going to be covering in the next video. 200 00:12:00,470 --> 00:12:01,910 But in summary of this video. 201 00:12:02,050 --> 00:12:05,050 We've seen that the cat command can be used to actually read out files. 202 00:12:05,050 --> 00:12:11,630 So if I look at Beautiful on our desktop, if I read out beautiful text, we can read that out. 203 00:12:11,650 --> 00:12:15,910 If we want to reverse files vertically, we can use tack. 204 00:12:15,940 --> 00:12:19,870 If we want to reverse files horizontally, we can use rev. 205 00:12:20,080 --> 00:12:22,090 But all either way, all of these. 206 00:12:22,210 --> 00:12:27,070 What they're doing is they are just reading a file's content and spitting it out to standard output 207 00:12:27,070 --> 00:12:31,990 where you can then of course pipe it into other commands to do other processing or like while you're 208 00:12:31,990 --> 00:12:36,520 working on the command line, if you just want to see quickly what's in a file, you can just you can 209 00:12:36,520 --> 00:12:42,300 just use cat the cat command and then see that really quickly and get on with what you were doing. 210 00:12:42,310 --> 00:12:42,700 Okay. 211 00:12:42,700 --> 00:12:45,370 So there we are those those are the cat tack and rev commands. 212 00:12:45,370 --> 00:12:50,170 But in the next video, we're going to take a look at how you can level up this ability to do more sophisticated 213 00:12:50,170 --> 00:12:50,440 things. 214 00:12:50,440 --> 00:12:53,320 So I'll break the video here and see you in the next video.