1 00:00:06,360 --> 00:00:08,190 - Okay, the next thing that we should talk about, 2 00:00:08,190 --> 00:00:12,030 which is related to files is using wildcards, 3 00:00:12,030 --> 00:00:14,880 also known as globbing. 4 00:00:14,880 --> 00:00:19,880 So, most file-oriented commands support using wildcards, 5 00:00:20,190 --> 00:00:22,980 as in ls a*, which is showing all files 6 00:00:22,980 --> 00:00:26,630 that have a name starting with an a, or ls a?*. 7 00:00:28,746 --> 00:00:32,010 The question mark stands for one single character 8 00:00:32,010 --> 00:00:34,260 one single character, any character, 9 00:00:34,260 --> 00:00:38,190 and the star is an unlimited number 10 00:00:38,190 --> 00:00:40,200 of unspecified characters. 11 00:00:40,200 --> 00:00:42,790 So, this will show you all files that have 12 00:00:44,185 --> 00:00:47,550 a name of at least two characters. 13 00:00:47,550 --> 00:00:51,510 Then, we have ls a and then [nm]. 14 00:00:51,510 --> 00:00:55,050 The nm between square bracket means either or, 15 00:00:55,050 --> 00:00:57,750 so either an m or an n. 16 00:00:57,750 --> 00:01:02,750 And what do you think of ls a[a-e], 17 00:01:02,970 --> 00:01:06,750 for anything between the a and the e. 18 00:01:06,750 --> 00:01:08,910 Also useful, is that many commands 19 00:01:08,910 --> 00:01:11,670 also support working with groups and ranges, 20 00:01:11,670 --> 00:01:16,350 as in touch file{1..100}. 21 00:01:16,350 --> 00:01:17,340 What is that doing? 22 00:01:17,340 --> 00:01:21,030 That is creating 100 files in one single command. 23 00:01:21,030 --> 00:01:25,950 Or what do you think of mkdir /data/{sales,account} 24 00:01:25,950 --> 00:01:29,820 which creates two directories in one. 25 00:01:29,820 --> 00:01:31,203 Let me demonstrate this. 26 00:01:33,930 --> 00:01:37,170 In order to demonstrate, I'm getting into the etc directory 27 00:01:37,170 --> 00:01:40,380 and in the etc directory I'm using ls b*. 28 00:01:40,380 --> 00:01:41,280 So what do we see? 29 00:01:41,280 --> 00:01:43,830 We see that it's showing files 30 00:01:43,830 --> 00:01:46,080 that have a name starting with a b, 31 00:01:46,080 --> 00:01:48,150 but then something weird is happening. 32 00:01:48,150 --> 00:01:50,880 It's also showing matching directory names 33 00:01:50,880 --> 00:01:52,560 and for matching directory names, 34 00:01:52,560 --> 00:01:56,400 it shows all the files it found in the directory. 35 00:01:56,400 --> 00:02:00,090 Now, that is exactly this thing that I just talked about. 36 00:02:00,090 --> 00:02:03,180 If you use ls -d b*, 37 00:02:03,180 --> 00:02:06,000 then we see directory names instead of directory contents. 38 00:02:06,000 --> 00:02:07,953 So that's probably so much better. 39 00:02:08,880 --> 00:02:13,690 Now let's use ls -d b*.?. 40 00:02:17,880 --> 00:02:19,410 Now, what is that? 41 00:02:19,410 --> 00:02:23,130 Well, let's try to understand ls b*. 42 00:02:23,130 --> 00:02:26,700 The star is for any character, but then there is a dot. 43 00:02:26,700 --> 00:02:30,510 That means that we need a dot in the name of the file. 44 00:02:30,510 --> 00:02:32,373 And then there is a question mark, 45 00:02:33,374 --> 00:02:35,250 which means that behind the dot 46 00:02:35,250 --> 00:02:37,350 we need one single character. 47 00:02:37,350 --> 00:02:41,700 And that is why we see bash_completion.d and binfnt.d 48 00:02:41,700 --> 00:02:44,460 because these are the only ones that have one character 49 00:02:44,460 --> 00:02:46,083 after the dot. 50 00:02:47,100 --> 00:02:49,230 So let's have a look at another example, 51 00:02:49,230 --> 00:02:54,230 ls [ab]???, and what is that showing, huh? 52 00:02:57,660 --> 00:02:59,520 It is showing files. 53 00:02:59,520 --> 00:03:01,890 And do these files match the pattern? 54 00:03:01,890 --> 00:03:03,810 Hey, everybody, 55 00:03:03,810 --> 00:03:06,930 take a second to think about what is happening here. 56 00:03:06,930 --> 00:03:08,820 You know what is happening? 57 00:03:08,820 --> 00:03:12,210 This is happening. Let's do ls -d. 58 00:03:12,210 --> 00:03:13,920 You remember what ls is doing 59 00:03:13,920 --> 00:03:16,530 when it finds the directory that matches the pattern? 60 00:03:16,530 --> 00:03:18,450 It doesn't show the name of the directory. 61 00:03:18,450 --> 00:03:20,760 It shows the contents of the directory. 62 00:03:20,760 --> 00:03:24,090 And if we put a -d in front of it, 63 00:03:24,090 --> 00:03:27,960 then we can see that it actually did what we asked it to do. 64 00:03:27,960 --> 00:03:32,960 ls -d [ab] plus ??? is looking for 65 00:03:33,720 --> 00:03:36,330 items that have a name consisting of four letters 66 00:03:36,330 --> 00:03:38,160 starting with an a or a b. 67 00:03:38,160 --> 00:03:41,520 The only matching item is alsa and without a -d, 68 00:03:41,520 --> 00:03:44,280 we see the contents of this alsa thing, 69 00:03:44,280 --> 00:03:46,950 and not really what we were looking for. 70 00:03:46,950 --> 00:03:48,780 As you can see, the output of ls 71 00:03:48,780 --> 00:03:50,880 sometimes is pretty confusing. 72 00:03:50,880 --> 00:03:55,867 Now, let me use ls [a-e]*, 73 00:03:57,930 --> 00:03:59,040 which is an easy one, 74 00:03:59,040 --> 00:04:02,700 as long as we don't forget to use the -d. 75 00:04:02,700 --> 00:04:04,890 Hey, that's also something we haven't seen before. 76 00:04:04,890 --> 00:04:06,960 I'm using the -d to the end. 77 00:04:06,960 --> 00:04:09,060 Can we do that? Yes, we can. 78 00:04:09,060 --> 00:04:12,300 Linux is a pretty flexible operating system 79 00:04:12,300 --> 00:04:15,450 and command line options can often be specified 80 00:04:15,450 --> 00:04:17,460 on the end of the command line as well, 81 00:04:17,460 --> 00:04:19,680 as we can see right here. 82 00:04:19,680 --> 00:04:21,870 Now, let's also talk about these ranges, 83 00:04:21,870 --> 00:04:25,410 and in order to do so, I'm going back to my home directory. 84 00:04:25,410 --> 00:04:30,060 I am using touch file one up to many. 85 00:04:33,450 --> 00:04:34,710 Should I do that many? 86 00:04:34,710 --> 00:04:38,400 No, Let me just make the point and let me use 100. 87 00:04:38,400 --> 00:04:43,400 And there we can see that it easily created 100 empty files. 88 00:04:44,010 --> 00:04:46,680 Use any number that you want, but be careful. 89 00:04:46,680 --> 00:04:51,000 And maybe you wanna use rm after it to removed that. 90 00:04:51,000 --> 00:04:52,980 I'm not sure if I should be talking about it 91 00:04:52,980 --> 00:04:56,850 because we haven't talked about rm yet, but rm is remove. 92 00:04:56,850 --> 00:05:00,360 And in this case, I think it's useful to do that. 93 00:05:00,360 --> 00:05:02,395 And what do you think of mkdir? 94 00:05:02,395 --> 00:05:06,783 Mkdir /data/{sales,account}. 95 00:05:09,000 --> 00:05:10,920 Now, this is an interesting one 96 00:05:10,920 --> 00:05:13,350 and you should know, everybody, that every now and then 97 00:05:13,350 --> 00:05:15,900 I like to show you things that go wrong. 98 00:05:15,900 --> 00:05:19,110 And as you can see, this is going wrong. 99 00:05:19,110 --> 00:05:20,580 Why is it going wrong? 100 00:05:20,580 --> 00:05:23,970 Well, not for one, but even for two reasons. 101 00:05:23,970 --> 00:05:26,610 Reason number one is that it is trying 102 00:05:26,610 --> 00:05:31,200 to create a complete directory path and we cannot do that. 103 00:05:31,200 --> 00:05:32,623 The error message that I'm getting here 104 00:05:32,623 --> 00:05:35,640 is that it is trying to create directory sales 105 00:05:35,640 --> 00:05:39,630 in the directory data but directory data does not exist. 106 00:05:39,630 --> 00:05:41,433 So, let me modify the command. 107 00:05:42,660 --> 00:05:44,220 Notice again that my cursor 108 00:05:44,220 --> 00:05:45,930 is at the end of the command line. 109 00:05:45,930 --> 00:05:48,570 I'm using control a to move my cursor 110 00:05:48,570 --> 00:05:50,490 to the start of the command line 111 00:05:50,490 --> 00:05:53,280 so that I can put a -p behind. 112 00:05:53,280 --> 00:05:54,150 Why am I doing that? 113 00:05:54,150 --> 00:05:56,640 I can do -p at the end of the command line. 114 00:05:56,640 --> 00:05:59,130 Yeah, I know, but for some reason I like it 115 00:05:59,130 --> 00:06:01,920 if my options come directly after the command, 116 00:06:01,920 --> 00:06:03,630 and there we go and uh-oh, 117 00:06:03,630 --> 00:06:05,940 different error message, permission denied. 118 00:06:05,940 --> 00:06:08,070 Of course we get a permission denied. 119 00:06:08,070 --> 00:06:10,200 We need sudo if you want to write 120 00:06:10,200 --> 00:06:12,360 into the root of the file system 121 00:06:12,360 --> 00:06:15,120 but with this command, it should be working 122 00:06:15,120 --> 00:06:18,300 after we enter, of course, the sudo password. 123 00:06:18,300 --> 00:06:19,710 There we go. 124 00:06:19,710 --> 00:06:24,710 And if I use ls /data, then we can see, 125 00:06:25,050 --> 00:06:27,240 and this time I wanted to see that 126 00:06:27,240 --> 00:06:30,630 we can see the content of the /data directly 127 00:06:30,630 --> 00:06:32,400 containing account and sales, 128 00:06:32,400 --> 00:06:34,050 and that's exactly what I wanted.