Hello everyone in this video we are going to talk about a very very powerful concept and tool in our
Linux command line which is the wild cards.
So a wild card is simply a symbol that represents
one or more characters
and one of the most famous wild cards out there is the asterisk or the store and this symbol represents
or matchers any characters any number of characters or any characters right.
And the other famous one is the question mark which represents or matches a single character.
So right now you might be lost and you might be asking yourself what are you talking about.
Don't worry I will show you what I'm talking about right now.
So right now I am on my desktop as you can see and I have many files and I also have a directory one
by one here and this directory is initially empty OK.
OK.
So so far we learned how to copy files into directories right.
But if I told you.
Now what if you want.
What of it.
What if what if I ask you to copy all these files here to the directory one all the files that I have
here to the directory one.
OK.
You might you would say OK this will take me a long time.
I have to specify all file names.
So I'll begin with one z z 3-G cats dogs even all the way until you reach this guy here.
1G one.
And then you specify your destination directory and you're right you can do it this way.
But have you noticed one thing it will take you forever to include all these file names without any
error and then copy them to the directory one instead.
We can use the asterisk.
So if I said C-p store directory one this will simply copy everything that I have here to directory
one.
So let's execute this command here.
And let's open directory one as you can see every file on my desktop was copied to my directory once.
So it's magic right.
So the store represents or matches any characters any number of characters or any category of characters.
Right.
And if I go to my directory one now and I want to remove all my files I just have to say or am store.
So our store will remove all the files that I have here.
As you can see very very efficient OG.
So let's go back to my directory one on my desktop.
So right now as you can see I have file one the text file to the text file through the text.
So what if I want to copy all these three files here.
I can say C.P file store directory one.
So if I want to copy file one text file to the text file through the text to my directory one all I
not all I want to say is just C.P. file store directory want.
You know why.
Because you're saying I want to copy all the files that begins with the named file or with the characters
file and I do not care about what foe's 5.
So if I could just command and go to my directory one and you can see I'm done.
Awesome.
And now I'm go to the rectory one and remove everything that I have and now it's clean again.
Awesome.
So you can see it now you can you have an idea of how the asterisk wildcard works.
And actually for example let's see here.
If you want to copy all the files that ends with the dot the XTi.
So here we have that XTi.
T XTi and the XTi.
So I would say C-p store.
I don't care what the name with a file.
But all I care about is that it ends with Dotti XTi and copy it to my directory 1.
So if I go open my directory one will see file 1.60 file 2.50 and file 3.50.
So as you can see the wildcard asterisk is very very powerful.
And actually you can say copy all the files.
So right now let's go to my directory once again and delete everything that I have clear my screen.
OK right now.
Right now I don't have anything on my directory one.
So let's move forward.
Let's say for example that you want to you want to copy all the files that begins with the letter.
The lower case letters G.
So here we have G1 G-2 and G-3.
So all you need to say is just C-p D-Star and then directory one and this will copy all the files that
begins with the letter G but actually so we have to go it on my desktop first and then I can do this.
So restore directly one and this will work as you can see I have one G-2 and G-3 here.
Awesome.
And now I got my direct one and move everything and go back.
Cool.
And let's do one more.
One more example of the asterisk here.
So let's say that you want to copy all the files that begins with the lowercase letter N so and you
don't care how long the file name is.
But if you want to make sure that it ends with an e..
So what do I mean here.
So here this will copy all the files that begins with the letter the lowercase letter and and ends with
the lower case letters.
So can you see any in any year.
Yeah I can see number number but the number four here it ends with the letter with a letter or two I
will not included this one will be included.
Number one because it begins with and ends with an end.
And this one will also be included because it begins with an end and also it ends with any.
So if I execute this command I have to I'm expecting two files to be there which is number one and number
three.
Let's see as you can see number one and number three.
Awesome.
So that's about the asterisk wildcard right.
Now we move our attention to the sink to the second wild card which is the question mark.
So the question mark is different and is very useful when you when you have like a certain number of
characters in mind.
So what do I mean by this.
Let's say for example that you say I want to copy all the files that begins with the uppercase or.
OK let's see let's think of an example here.
Yeah.
I want to copy all the files that begins with named file and I don't care at the other what is the next
character here but I want it to be text not the XTi directory one.
So what I'm saying here as we know that question mark represents a single character.
So unlike unlike the store or the asterisk which represents any character the question mark represent
represents a single character.
So here what I'm saying is that I want to copy all the files that have file that begins with a with
the name file but I do not care what the other character that follows here.
And then Datti XTi.
So as know this will include file 1.60 file that takes the file through the text the but before I do
this I have to I want I want to go to the rectory one and remove everything.
And actually I want to include another file here which is called File 50 to 60.
I will tell you why I include fine.
So if I said C-p file that the XTi OK can you expect what this command will execute.
OK I'll tell you right now we'll show.
So if you go to the rectory one we can only see C-3 file which is file one file to and file three.
So you might be wondering why it did not include file 52 for example that the XTi because it's different.
The question mark is different
compared to the asterisk because near all I only included one character here which is the question mark.
So this question mark and B can represent only one character which is here 2 3 or 1.
But here I have two characters fifty two.
So in order to represent these two characters I have to say file star star that the XTi directory one
and this will be filed 52 that the XTi as you can see here.
So it is quite different.
The question mark is very very different compared to the asterisk so let's do this one more time to
make sure we understand the difference so I'll delete everything that I have in my directory one and
so if he says files store the XTi this will include all the guy's file 1 file to file 3 and file 52.
Because store here there is no restriction on the number of characters here.
So here it will take all the four files as you can see.
However if I delete all the guys here and then I put a question mark instead of an asterisk it will
only take the guy's file one file to find three because I question mark and only matches or represent
a single character OK.
I hope you guys understand now the difference between a question mark and an asterisk.
OK.
Let's do more examples of the question mark.
So let's say I want to I want to copy all the files that begins
with an uppercase p
and.
OK.
I see.
No actually let's say that we want to copy all the files that begins with the with number and followed
by three characters.
OK so what do you think this command will execute.
So if he if he if you look or if you look here we have four files that begins with number.
Number four number one.
Number three.
Number two.
However here I said that I am only interested in those files that are that begin with number and are
followed by exactly three characters.
So number four will not be included because four here has four characters.
One will be included because only one has three characters.
Three will not include included because three has five characters but two will be included because two
has three characters.
So in summary number one and number two are the ones that should be included.
OK.
So if now execute this command and I open my directly one I am expected to see two files exactly number
one and number two awesome.
So as you can see the question mark here represents a single character and it is very very useful when
you have like a certain number of characters in mind right unlike the the asterisk.
So if you actually delete this one here and you did the exact same thing but with a store.
So what this command will execute is simply all the files.
Number four number one number three.
Number two because a store here represent anything.
So here I am saying copy all the files that begins with number followed by any anything.
And you can see 4 2 1 3 2.
Awesome.
OK.
Let's leave this one here and let's do one more example before we end video.
OK.
Actually we can we can combine the store and the question mark.
So how can we do this.
It is very simple.
So I would say copy all the files that begins with is f followed by actually no file followed by a number.
And I don't care because this will not work.
Let's think of another example let's think of an example that can combine the question mark and the
asterisk.
OK
so this one should be not that hard.
Ok I will say and copy all the files that begins with the letter f followed by
1 followed by a as I think character that I'm not interested in and then L and then anything that I'm
told that the XTi and copy this to my Reiki 1.
So this is kind of messy here.
What I'm saying is basically copy all the files that begins with the letter S followed by a letter that
I'm not interested in and then followed by L and any other character until the dx d.
So this will simply copy files one file to file three and file 52 two because all of these guys begin
with an f followed by an a character which isn't I.
And then all these guys also end with the extreme.
So if I execute this command I will have four files you file one file to file three for fifty two.
So I did this command because I just wanted you I wanted you to know that you can combine wild cards.
The question mark and the asterisk so there are other wild cards that we did not discuss in this video.
But we will discuss in the next video.
So right now just practice with these two guys here the asterisk and the question mark.
OK.
So.