1 00:00:00,000 --> 00:00:03,180 Now it's time to look at the last command, which 2 00:00:03,210 --> 00:00:06,600 is wc. It is one of the last command for text 3 00:00:06,600 --> 00:00:09,300 processors that in our lectures, that we are going 4 00:00:09,300 --> 00:00:14,820 to cover. A wc stands for word count, and what 5 00:00:14,820 --> 00:00:19,290 exactly it does. The command reads either standard 6 00:00:19,290 --> 00:00:22,680 input or a list of files and generates newline 7 00:00:22,680 --> 00:00:26,400 count, word count, and byte count. So if you just 8 00:00:26,400 --> 00:00:30,360 run wc on a file, it will give you these three 9 00:00:30,390 --> 00:00:33,180 output. Now let's get into our Linux machine. And 10 00:00:33,180 --> 00:00:35,940 I have the first command, as you all know, is to 11 00:00:35,940 --> 00:00:38,700 check the version and to get the help. So when I 12 00:00:38,700 --> 00:00:41,910 get to my Linux machine, and again, I'm logged 13 00:00:41,910 --> 00:00:43,830 into the PuTTY, and you guys know what we have to 14 00:00:43,830 --> 00:00:47,520 run, we have to run, as usual the username, and the hostname, 15 00:00:47,520 --> 00:00:50,580 and which directory we are in. And pretty much 16 00:00:50,580 --> 00:00:53,520 once we confirm, perfect, clear the screen, and now do 17 00:00:53,550 --> 00:00:57,030 wc, and I'm going to skip version. I know all of 18 00:00:57,030 --> 00:00:59,820 you guys know this already by now, these are the 19 00:00:59,820 --> 00:01:04,019 few options that it is it supports. And then the 20 00:01:04,019 --> 00:01:09,000 one of the most used one that I use as 21 00:01:09,000 --> 00:01:11,220 well, and a lot of people use is -l, which 22 00:01:11,220 --> 00:01:14,190 we'll cover in a few. So now let's get into the 23 00:01:14,190 --> 00:01:18,330 next command, which is wc file name. Let's clear 24 00:01:18,330 --> 00:01:21,540 the screen. I'm going to go to my seinfeld 25 00:01:21,540 --> 00:01:24,774 directory, and in there I have my seinfeld-characters. Let's 26 00:01:24,774 --> 00:01:26,670 cat out, and these are the 27 00:01:26,670 --> 00:01:29,860 contents. This is the content of my seinfeld-characters file. 28 00:01:29,860 --> 00:01:32,700 Perfect. Now if I do, let's 29 00:01:32,700 --> 00:01:36,664 clear the screen again, if I do wc seinfeld-characters, 30 00:01:36,664 --> 00:01:39,000 hit enter, you're going to see it will 31 00:01:39,000 --> 00:01:42,720 tell me exactly what's inside, meaning, it has 17 32 00:01:42,720 --> 00:01:50,670 lines, has 34 words, and 236 bytes. So if I wanted 33 00:01:50,670 --> 00:01:54,300 to know only the line numbers that's inside of 34 00:01:54,300 --> 00:01:57,300 seinfeld-character, I could simply do wc, word 35 00:01:57,300 --> 00:02:01,440 count, or sometimes people refer to as waca dash 36 00:02:01,470 --> 00:02:04,440 l, and seinfeld-characters, you're going to see it 37 00:02:04,440 --> 00:02:07,710 will give me only the number of lines, that is 17. 38 00:02:07,890 --> 00:02:12,570 Similarly, I could do either w or b to get the 39 00:02:12,570 --> 00:02:16,740 word count, and the byte count. So for the word, as 40 00:02:16,740 --> 00:02:20,490 you see, it'll give me 34. For the byte count, I'll 41 00:02:20,490 --> 00:02:22,225 replace it with b, 42 00:02:22,225 --> 00:02:24,675 [No audio] 43 00:02:24,675 --> 00:02:26,734 is it a byte count, why it's 44 00:02:26,760 --> 00:02:29,220 not giving me the information, invalid option minus 45 00:02:29,220 --> 00:02:35,070 b. For the byte count, hmm, that's new. Okay, let 46 00:02:35,070 --> 00:02:39,270 me check why is that, wc --help, and we will 47 00:02:39,270 --> 00:02:42,990 see, ah for the byte it's actually c. See, that's 48 00:02:42,990 --> 00:02:46,530 why it's so important for you to run wc dash dash 49 00:02:46,530 --> 00:02:50,550 help to find out the right option. Or, what's the 50 00:02:50,550 --> 00:02:54,240 other one, the big one man wc, which will also 51 00:02:54,240 --> 00:02:57,420 give you a lot of information about that specific 52 00:02:57,420 --> 00:03:00,960 command. Anyway, my slide is showing -b, that 53 00:03:00,960 --> 00:03:03,810 is okay, you could ignore it. I'll go back and fix 54 00:03:03,810 --> 00:03:06,750 it later. But for now, for this lecture, we'll go 55 00:03:06,750 --> 00:03:12,930 continue with wc -c for byte size. Also, a 56 00:03:12,960 --> 00:03:15,300 lot of people confuse this with the -c, 57 00:03:15,300 --> 00:03:17,610 meaning characters, it is not a character, it's exactly a 58 00:03:17,610 --> 00:03:21,210 byte size. So the file name would be seinfeld. 59 00:03:21,840 --> 00:03:24,810 Usually we saw a bytes and characters are 60 00:03:24,810 --> 00:03:29,280 somewhat similar, maybe a few, not exactly a few, 61 00:03:29,340 --> 00:03:31,950 two or three numbers up and down. But anyway, 62 00:03:31,950 --> 00:03:34,740 focus on wc -c, if you wanted to get the 63 00:03:34,740 --> 00:03:38,940 byte size. Alright, the next command I have the wc 64 00:03:38,940 --> 00:03:41,520 DIRECTORY, which is NOT allowed. So if you trying 65 00:03:41,520 --> 00:03:44,880 to do the wc on a directory, so let's say inside 66 00:03:44,880 --> 00:03:48,180 of my seinfeld directory, there is no directory. 67 00:03:48,180 --> 00:03:51,510 So I'll go one step back, and do ls -l to see 68 00:03:51,510 --> 00:03:54,330 which directories are there. And now I will do wc 69 00:03:54,330 --> 00:03:57,690 on seinfeld directory, hit Enter. It will say, wc: 70 00:03:57,690 --> 00:04:00,210 seinfeld/: Is a directory. So it's not going to 71 00:04:00,210 --> 00:04:02,310 give me any information that I'm looking for 72 00:04:02,310 --> 00:04:05,640 regarding lines, or word count, or bytes. Anyway, 73 00:04:05,640 --> 00:04:09,420 clear the screen. Let's go to the next one, and 74 00:04:09,450 --> 00:04:12,930 which is the ls -l command, which we will run, 75 00:04:13,560 --> 00:04:16,680 and that will give us the list of output. Again, 76 00:04:16,680 --> 00:04:19,320 this is the command one. Before we were talking 77 00:04:19,320 --> 00:04:22,110 about reading from the file, now this is reading 78 00:04:22,110 --> 00:04:25,230 from the output of a command. So if you want to 79 00:04:25,260 --> 00:04:28,200 see how many files that you have, let's say your 80 00:04:28,200 --> 00:04:31,350 boss comes to you and says hey, listen, I need the 81 00:04:31,380 --> 00:04:34,290 list of files we have in this user home directory. 82 00:04:34,320 --> 00:04:37,770 Give me the number. You go in and you quickly run 83 00:04:37,770 --> 00:04:41,580 ls -l, and wc -l, and you come back to him 84 00:04:41,580 --> 00:04:45,630 and or her and tell your boss, hey, we got 15 85 00:04:45,630 --> 00:04:46,530 files alright. 86 00:04:47,700 --> 00:04:51,150 wc is working perfectly here, and it is giving you 87 00:04:51,210 --> 00:04:54,840 the count of every line. But in fact you do not 88 00:04:54,840 --> 00:04:58,230 have for 15 files or directories you have 14. Why 89 00:04:58,230 --> 00:05:02,340 because, you see this total 280 here, this is 90 00:05:02,340 --> 00:05:06,030 something that it is also counting. So, always 91 00:05:06,030 --> 00:05:09,600 remember when you do ls -l, and wc -l, 92 00:05:09,780 --> 00:05:13,500 whatever the results that you get, always minus it 93 00:05:13,500 --> 00:05:17,010 with one. So, now you could say that I have 14 94 00:05:17,010 --> 00:05:20,220 files and directories altogether. What if I want 95 00:05:20,220 --> 00:05:24,017 to know only the list of directories in my, 96 00:05:25,719 --> 00:05:29,520 in my home directory. So, to do that, you know, to list 97 00:05:29,520 --> 00:05:32,010 the directories, you have to run the command, I 98 00:05:32,010 --> 00:05:38,460 think ls -ld, or ls -ld /homes 99 00:05:39,600 --> 00:05:41,051 /iafzal. 100 00:05:41,051 --> 00:05:43,087 [No audio] 101 00:05:43,087 --> 00:05:44,855 Okay, it is giving me, 102 00:05:44,855 --> 00:05:48,009 [No audio] 103 00:05:48,009 --> 00:05:50,730 all, okay, so this is not the right command. Anyway, I will 104 00:05:50,730 --> 00:05:53,040 look it up for what is the right command, however, 105 00:05:53,040 --> 00:05:55,740 I could still use another trick. See, that's why 106 00:05:55,740 --> 00:05:58,710 Linux is so powerful. And you do ls -l, you 107 00:05:58,710 --> 00:06:02,370 you notice that every directory starts with D. So 108 00:06:02,370 --> 00:06:06,090 what I'm going to do is I'm going to do ls -l, 109 00:06:06,210 --> 00:06:10,140 and grep for drw, because all of them, if you 110 00:06:10,140 --> 00:06:14,520 notice starts with drw, drw. So just give me 111 00:06:14,520 --> 00:06:16,740 all the directory. So by default,now, I have all 112 00:06:16,740 --> 00:06:20,010 the directories. Anyway. So now if I want to know 113 00:06:20,010 --> 00:06:22,050 how many directories I have, hit up arrow key, and 114 00:06:22,050 --> 00:06:27,690 do wc -l. So it is telling me that I have 11 115 00:06:27,690 --> 00:06:31,260 directories. Now, it is not giving me that total, 116 00:06:31,680 --> 00:06:34,050 right here, you notice, because the total will 117 00:06:34,050 --> 00:06:37,560 only give you when you only run ls -l. As 118 00:06:37,560 --> 00:06:40,530 soon as you run ls -l, and pipe it that total 119 00:06:40,530 --> 00:06:43,617 will go away, and then you will just grep for drw, 120 00:06:43,617 --> 00:06:45,750 because you're only grepping for anything that 121 00:06:45,750 --> 00:06:48,780 starts with drw. And the total does not start 122 00:06:48,780 --> 00:06:53,610 with drw. Anyway, as an exercise for 123 00:06:53,610 --> 00:06:58,714 you, go ahead and find out the command of ls -ld, 124 00:06:58,714 --> 00:07:01,230 or whatever the command is and find out which 125 00:07:01,230 --> 00:07:03,420 command will give you only the directories. I use 126 00:07:03,420 --> 00:07:06,090 the grep, it works for me perfect. But anyway, 127 00:07:06,090 --> 00:07:07,950 there is, I'm definitely sure there is a command 128 00:07:07,950 --> 00:07:09,600 and I'm sorry, I didn't know that. 129 00:07:09,750 --> 00:07:12,600 Anyway, that's for you to find out. So that's how 130 00:07:12,600 --> 00:07:15,480 you know the number of files in your directories 131 00:07:15,480 --> 00:07:18,060 in your home directory. And then the last command 132 00:07:18,060 --> 00:07:21,300 that we will run is to grep for keyword in a 133 00:07:21,300 --> 00:07:25,380 file and then get a list of it. So I'll go back to 134 00:07:25,380 --> 00:07:28,110 my seinfeld directory. In the seinfeld directory, I 135 00:07:28,110 --> 00:07:31,830 have a file seinfeld, as everybody know, so I'll 136 00:07:31,830 --> 00:07:36,090 do cat seinfeld. And here I will grep for 137 00:07:36,390 --> 00:07:42,580 seinfeld. So grep Seinfeld, in my seinfeld-characters 138 00:07:42,580 --> 00:07:44,850 file, and you'll notice there are three 139 00:07:45,300 --> 00:07:48,600 people with this last name Seinfeld. Now if I want, 140 00:07:48,630 --> 00:07:51,840 if I had let's say 20 or 30 or 1000 of those names 141 00:07:51,840 --> 00:07:54,570 that match my criteria, then how would I know how 142 00:07:54,570 --> 00:08:00,142 many were there? So simply do pipe it wc and -l, 143 00:08:00,142 --> 00:08:02,490 it will tell you there are three instances of 144 00:08:02,490 --> 00:08:06,630 your search criteria, works, perfect. I hope you 145 00:08:06,630 --> 00:08:09,420 understand now all the text processing commands, I 146 00:08:09,420 --> 00:08:13,050 have explained it in very detail. Please please do 147 00:08:13,050 --> 00:08:15,930 try them with different options and different 148 00:08:15,930 --> 00:08:18,750 scenarios and see which ones works for you and 149 00:08:18,750 --> 00:08:20,670 which ones gives you more fun to work with. 150 00:08:20,670 --> 00:08:22,442 [No audio]