1 00:00:00,000 --> 00:00:01,680 [No audio] 2 00:00:01,680 --> 00:00:06,780 Wildcards. What are wildcards? Just as the name 3 00:00:06,780 --> 00:00:11,800 says they are wildcards, meaning if you play cards, 4 00:00:11,800 --> 00:00:14,737 [No audio] 5 00:00:14,737 --> 00:00:19,140 and you know in Poker, or Blackjack, 6 00:00:19,260 --> 00:00:23,250 they do pick a card, like 10 or 9, whatever the 7 00:00:23,250 --> 00:00:26,580 card and you could match it to any of the cards to 8 00:00:26,580 --> 00:00:29,430 make your flash, trail, or whatever that you like. 9 00:00:29,430 --> 00:00:33,360 So that is kind of a wildcard. So just like that, 10 00:00:33,360 --> 00:00:37,470 in Linux, we use wildcards to get the output that 11 00:00:37,470 --> 00:00:41,880 we are looking for. A wildcard is a character, now 12 00:00:41,880 --> 00:00:44,670 this is a definition right from the Linux 13 00:00:44,670 --> 00:00:48,600 dictionary, that can be used as a substitute from 14 00:00:48,630 --> 00:00:53,040 any of a class of characters in a search. So there 15 00:00:53,040 --> 00:00:56,610 are many wildcards, but the most basic ones I have 16 00:00:56,610 --> 00:00:59,730 listed here, there are three. The first one is the 17 00:00:59,730 --> 00:01:02,580 one I use most of the time is asterisk, which is 18 00:01:02,580 --> 00:01:05,910 also referred to as a star. A star represents 19 00:01:05,940 --> 00:01:09,120 zero or more characters, anything that matches 20 00:01:09,150 --> 00:01:12,870 that star placeholder. We'll look into that in a 21 00:01:12,870 --> 00:01:17,010 moment when we actually use the star wildcard in 22 00:01:17,010 --> 00:01:20,250 our Linux machine. Then we have a question mark, 23 00:01:20,280 --> 00:01:24,540 represents a single character. So if you have a 24 00:01:24,540 --> 00:01:29,730 file name, text, and you are looking for any files 25 00:01:29,910 --> 00:01:34,200 that has the word text, and you could use T E, 26 00:01:34,440 --> 00:01:37,470 instead of x, you could just put question mark in 27 00:01:37,470 --> 00:01:40,800 there, and then t, that means what ever falls that 28 00:01:40,800 --> 00:01:45,810 had T E doesn't matter what's inside of the x and 29 00:01:45,810 --> 00:01:50,040 the last letter is x, the t, that didn't work. The 30 00:01:50,040 --> 00:01:52,860 third one we have brackets, which represents a 31 00:01:52,860 --> 00:01:56,160 range of characters. So it's better we look at 32 00:01:56,190 --> 00:02:00,900 done Linux machine to understand them more deeply. 33 00:02:02,370 --> 00:02:04,560 I'm going to bring up my machine real quick. 34 00:02:05,340 --> 00:02:09,240 Where'd it go? Right here. I'm logged in always as 35 00:02:09,240 --> 00:02:13,919 myself. And I'm in my home directory, of course. 36 00:02:14,310 --> 00:02:18,270 Now, right now, these are the files and 37 00:02:18,270 --> 00:02:21,870 directories in exist in my home directory, I want 38 00:02:21,870 --> 00:02:27,810 to create nine files that has a name, let's say 39 00:02:28,140 --> 00:02:33,360 abcd, one, and xyz. And then same thing instead of 40 00:02:33,360 --> 00:02:37,350 one, it just increments the number 23456. I could 41 00:02:37,350 --> 00:02:43,710 do this touch abcd1-xyz, one 42 00:02:43,710 --> 00:02:47,370 time, then hit up arrow key again, change one to 43 00:02:47,370 --> 00:02:52,110 two, change two to three, and keep going. But don't 44 00:02:52,110 --> 00:02:54,870 you think it's cumbersome and tedious? It is right. 45 00:02:54,990 --> 00:02:58,500 So we use wildcard to perform that task because 46 00:02:58,500 --> 00:03:01,530 you're going to create nine files. So it's just a 47 00:03:01,590 --> 00:03:05,040 practice that we are doing for nine files. Trust 48 00:03:05,040 --> 00:03:07,620 me, in corporate environment, you probably going 49 00:03:07,620 --> 00:03:09,660 to have to create like 1000s of files, what you're 50 00:03:09,660 --> 00:03:12,090 going to do, you're going to just hit up arrow key 51 00:03:12,270 --> 00:03:15,720 and type it 1000 times. No, that's not 52 00:03:15,720 --> 00:03:18,840 productive. So then what do you do? We use 53 00:03:18,840 --> 00:03:22,650 wildcards. So first of all, I'm going to do is I'm 54 00:03:22,650 --> 00:03:26,730 going to remove these files one by one. Again, I 55 00:03:26,730 --> 00:03:31,290 can remove it wildcard, as well. But let's create 56 00:03:31,290 --> 00:03:35,550 it first and I'll show you how I can remove it. So 57 00:03:35,820 --> 00:03:38,400 I have two left. Now I could use a wildcard to 58 00:03:38,400 --> 00:03:44,550 remove both in one shot, remove abc wildcard. So 59 00:03:44,550 --> 00:03:47,760 what is telling it, remove everything that has a 60 00:03:47,760 --> 00:03:50,640 file name that starts with abc and whatever that 61 00:03:50,640 --> 00:03:52,950 comes afterwards, you don't care, just remove it. 62 00:03:53,490 --> 00:03:56,520 I hit enter, ls -ltr, and you'll see all 63 00:03:56,520 --> 00:03:59,730 those two files are gone. Now I'm going to create 64 00:04:00,600 --> 00:04:03,960 nine files. And to create nine files, I'll use the 65 00:04:03,960 --> 00:04:06,390 command touch. As you know the touch is a command 66 00:04:06,390 --> 00:04:09,330 to use, and then there's a wildcard another 67 00:04:09,330 --> 00:04:14,970 wildcard that's called curly braces. So I was 68 00:04:14,970 --> 00:04:19,680 creating file abcd curly braces 1 dot dot 9, 69 00:04:19,680 --> 00:04:22,350 because I'm going to create nine files. So this 70 00:04:22,529 --> 00:04:25,350 curly braces 1 dot dot 9 starting to create nine 71 00:04:25,350 --> 00:04:28,740 files that has the digit one through nine and dash 72 00:04:29,070 --> 00:04:33,390 xyz. When I run this command, what do you think 73 00:04:33,390 --> 00:04:37,080 that I will have listed in my home directory? I 74 00:04:37,080 --> 00:04:43,140 will have nine files right here at the bottom, you 75 00:04:43,140 --> 00:04:50,040 will see I have nine files. Awesome, right? This 76 00:04:50,040 --> 00:04:51,090 is what you wanted to do. 77 00:04:51,090 --> 00:04:53,430 [No audio] 78 00:04:53,430 --> 00:04:57,510 It is much more faster to do in the wildcard as 79 00:04:57,510 --> 00:05:01,320 opposed to typing one by one. So let's use 80 00:05:01,320 --> 00:05:04,350 the asterisk, I just want to list every 81 00:05:04,350 --> 00:05:08,730 file name that starts with abc. You do abc 82 00:05:09,060 --> 00:05:11,820 asterisk, and you will have all the files that 83 00:05:11,820 --> 00:05:16,890 starts with abc. I want to remove every file that 84 00:05:16,890 --> 00:05:22,098 starts with abc. You could remove one by one, abcd1 85 00:05:22,098 --> 00:05:24,420 and so on, and so forth, again, very 86 00:05:24,420 --> 00:05:26,820 cumbersome, don't do it. You're a system 87 00:05:26,820 --> 00:05:29,310 administrator, you are smart, folks, you don't 88 00:05:29,310 --> 00:05:32,130 want to use the commands one by one, what do you 89 00:05:32,130 --> 00:05:35,310 would use, you'll use a wildcard. So you will do 90 00:05:35,550 --> 00:05:41,100 abcd, or ab, and do asterisk. The reason I 91 00:05:41,100 --> 00:05:44,160 picked the four letters, because if I just pick a 92 00:05:44,340 --> 00:05:47,520 and hit asterisk, it will also remove any other 93 00:05:47,520 --> 00:05:51,090 files in my home directory that starts with a and 94 00:05:51,090 --> 00:05:54,150 which I don't want it to do it. Right now, I don't 95 00:05:54,150 --> 00:05:57,090 have any files. So let's say if I create a file 96 00:05:57,090 --> 00:06:04,320 touch a. So now I have all the files and a. So I 97 00:06:04,320 --> 00:06:06,840 just want to confirm I don't have a so I don't 98 00:06:06,840 --> 00:06:09,720 delete any file accidentally. So yes, I don't have 99 00:06:09,720 --> 00:06:12,990 any file that begins with a other than these. So 100 00:06:13,020 --> 00:06:17,130 if I just do remove a asterisk, it will remove all 101 00:06:17,130 --> 00:06:20,970 the files that starts with a. Let's check it. 102 00:06:20,970 --> 00:06:23,340 [No audio] 103 00:06:23,340 --> 00:06:26,730 See, all those files are gone. Isn't that cool? 104 00:06:27,000 --> 00:06:30,420 Yes, it is. I love this asterisk because I use it 105 00:06:30,450 --> 00:06:35,700 all the time. I'm going to recreate those files 106 00:06:35,700 --> 00:06:39,450 again, by hitting up arrow key that will return my 107 00:06:39,450 --> 00:06:44,190 last ran command. Just confirm they are there. Now 108 00:06:44,190 --> 00:06:47,400 what if I want to remove everything that ends with 109 00:06:47,400 --> 00:06:51,510 xyz, same way remove, but this time we'll put 110 00:06:51,540 --> 00:06:56,790 asterisk in front of xyz, hit enter, boom, all 111 00:06:56,790 --> 00:07:01,230 gone. Also, I'm going to recreate it just for the 112 00:07:01,230 --> 00:07:06,990 exercise of this lesson. It created nine files. 113 00:07:07,020 --> 00:07:10,200 Now we'll move on to the next wildcard which is 114 00:07:10,200 --> 00:07:13,920 the question mark. The next question mark is 115 00:07:13,920 --> 00:07:22,312 telling it ls -l ?bcd*. 116 00:07:22,312 --> 00:07:26,190 Okay, what am I asking here, I'm asking is 117 00:07:26,220 --> 00:07:30,390 give me all the files that has whatever the 118 00:07:30,390 --> 00:07:34,770 character is the first, as long as the other 119 00:07:34,770 --> 00:07:37,890 characters has bcd, and whatever comes 120 00:07:37,890 --> 00:07:42,150 afterwards. These are the matching files because 121 00:07:42,240 --> 00:07:44,430 whatever the first character is, whether it's a or 122 00:07:44,430 --> 00:07:47,490 not, I don't care. I just want to make sure I will 123 00:07:47,490 --> 00:07:50,460 get the listing of the files that has bcd in it 124 00:07:50,460 --> 00:07:55,200 after the a. So that's how you use question mark. 125 00:07:55,410 --> 00:08:00,960 And the last one we have brackets. Bracket is going 126 00:08:00,960 --> 00:08:09,510 to tell me that give me anything that has c or d 127 00:08:09,510 --> 00:08:14,550 letter in a file. It's just that simple. Either c 128 00:08:14,580 --> 00:08:18,300 or the d, either f or this and that. So you put 129 00:08:18,330 --> 00:08:20,550 all that stuff that you're looking for inside of 130 00:08:20,550 --> 00:08:23,970 the bracket. And you will have all those files you 131 00:08:23,970 --> 00:08:26,250 see here. And it went so fast. So I'm going to put 132 00:08:26,250 --> 00:08:30,480 it in more output, I want to see one page at a 133 00:08:30,480 --> 00:08:34,289 time. And you'll see it gave me and it has a, it 134 00:08:34,289 --> 00:08:37,919 has b, every file that I'm getting as either has a 135 00:08:37,980 --> 00:08:42,210 or b either has a or b. So that's how it works. 136 00:08:42,210 --> 00:08:46,320 That's how wildcard works. Again, now I want to 137 00:08:46,320 --> 00:08:52,350 get rid of all the files that has x and y in it. 138 00:08:53,400 --> 00:08:56,429 Awesome, I have my wildcard I'm not going to go 139 00:08:56,429 --> 00:09:01,830 and delete one by one. So this command is telling 140 00:09:02,580 --> 00:09:06,900 the show that go ahead and please delete all the 141 00:09:06,900 --> 00:09:11,670 files that has x and y in it. And x and y has to 142 00:09:11,670 --> 00:09:15,210 be together of course. So if we do have these 143 00:09:15,210 --> 00:09:17,790 matching files xy and it will go ahead and delete 144 00:09:17,790 --> 00:09:23,520 it. And all of them are gone. So wildcard not 145 00:09:23,520 --> 00:09:26,850 necessarily is used just with ls or remove. You 146 00:09:26,850 --> 00:09:30,300 could use it with any of the commands we have. You 147 00:09:30,300 --> 00:09:33,060 could use it with all the commands we have learned 148 00:09:33,060 --> 00:09:37,350 so far. Try it. Try it with different commands. If 149 00:09:37,350 --> 00:09:40,590 it doesn't work, that's okay. Go online, google it 150 00:09:40,590 --> 00:09:45,030 and try wildcard, wildcard examples. Try them, 151 00:09:45,060 --> 00:09:47,580 just get familiar with them. This will help you a 152 00:09:47,580 --> 00:09:49,682 lot in your job, I promise you. 153 00:09:49,682 --> 00:09:58,101 [No audio]