Hello everyone.
In this demo, I'm going to show you how to use the find command.
Find command searches for lists, files and directories.
I also can use conditions with find command.
For example, I can use names, file type size users, groups, permissions and so on.
Let's apply some examples to show how to use the find command.
First, I'm going to type find.
Then I would like to type from where to start the search.
So in this case I would like to type dot, which means I would like to start the search from this current
working directory.
So the current working directory is the slash route.
Then type.
That's the type that like the type either files or directories that I would like to to do the search.
So in this example, I would like to do the search for files.
Then I hit enter.
As you can see here, we get all the files under this current working directory.
If I would like to do another example, same thing I will do this time under Slash home.
So I would like to start the search from slash home.
Then the type directory hit enter.
So as we can see here, we got all the directories under the slash home.
If I would like to find all the text files using the option dash name.
So let's do that.
I'm going to do the search from the current working directory, then the name, then the name.
I would like to mention what exactly I'm going to search, so I'm going to search for the dot txt.
So I'm going to as we can see here, I'm going to look for all the names.
It doesn't matter uppercase lowercase because we wrote here the star.
Then that d t.
So this is the extension that I would like to look for all the files that has the extension txt.
As you can see here I have to type the star dot txt under quotation mark.
Then I hit enter.
As we can see here, we got all the files.
It doesn't matter.
We didn't in this case we didn't mention the type because we already said that we would like to get
all the files or the text files under the current working directory.
If I would like to do the ignorecase, let's see if we do have for example, we don't.
I'm going to first I'm going to create two directories.
So as we can see here, it's lowercase.
Then here I'm going to do this uppercase and I hit enter.
As you can see here, we have two directories.
Now, if I would like to do the search in this current working directory and.
Dash name then.
Dir.
And we will hit enter.
So as we can see here, we got one output.
However, if I would do the dash I name, so I name means that it's ignoring case so it's going to ignore
either uppercase or lowercase.
I hit enter as we can see here.
We got what?
Two outcomes.
So because we added the I here, so it is the ignoring case.
So it doesn't matter if it's uppercase or lowercase.
Now if I would like to use the dash delete to delete this directory.
So first I'm going to find.
Dot the current working directory I name before I'm going to do that.
lSl So what I'm going to do here, I'm going to delete these two directories.
So find then dot, then I name, then dir, then I'm going to add another option here.
Dash, delete and hit enter lSl.
As we can see here, we don't have these two directories anymore.
If I would like to use the option here under under under home, I'm going to do option dash size, so
I'm going to look.
For doesn't matter file or directories under the slash home.
The working directory here.
The slash home.
Then I'm going to say, for example, 20 Mega.
So I'm going to look for all five directories that has the size 20 mega.
I hit enter.
We didn't get any outcome.
However, I can change the search from where I can start, so I'm going to start from the top.
From the top level, from the root directory or the root file system and hit enter and wait for a bit.
As we can see here, we got all the out, all the files and directories that has size 20.
Now let's move on if I would like to use another option.
So we're going to do here the current working directory first, then the type I'm going to do file.
Then.
Dash So in this case, in this example, I'm going to use the permission.
So this is the short for permission, dash perm.
So then I'm going to type the permission.
066.
We will talk more about the permissions and the file ownership and permission levels in the next level,
in the next chapter when we're going to explain more about how we can use these permissions hit enter.
We didn't get an outcome.
However, I can start from the top level.
I hit enter.
As we can see over here, we got all the files and directories that has the permission.
066, six.
And now we're going to do the example about how we can use the users so clear find I'm going to start
here and this current working directory then type.
I'm going to do directory this time, then dash user.
So I'm going to look for all the directories that belongs to this user.
So the user student and I hit enter didn't get anything.
However, if I will change to start from the top level hit enter.
As you can see here we got all the directory directory is here under this user or that or the or the
directory that belongs to this user.
I can do the same thing if I would like to for example, do group, then we have a group student hit
enter.
So you can see here we get.
All the directories that belongs to group student.
Now let's move on to another example here.
So another example, if I would like to do.
Search.
If I would like to search text within multiple files.
So the multiple files here, for example, I'm going to do cut month first.
As we can see here, we have this text file and I would like to search, for example, for the month
March.
So I'm going to search for a keyword here.
So I'm going to do find first, then dot the current working directory, then the type.
So the type will be F, so the file text file, then the name here.
So in this here, the name I have to say.
What is it before so I name so I'm going to look for it doesn't matter which is the file.
So it's not a specific.
I'm not I'm not I'm not looking for a specific file for that text.
Then after that dash.
So I'm going to use another option here.
E x.
E c.
So e x e c.
This is the option that I would like.
So this is an execute command.
I'm going to execute this command after the search.
Then I'm going to use the grip command.
Then after the grip between a single quotation, for example, I'm going to search for.
The word march, then close to the quotation mark.
The single quotation mark.
So the single quotation mark here.
Then after that, what I'm going to use with the presses, I have to do like that.
Then space, then the backslash, then semicolon.
So we need to understand the structure.
If I would like to use the execute command.
This is how this is how it how it works.
So I'm going to use the execute in order to run another command.
After the find or the search command.
Then grip.
So what I'm going to do grip the word marsh Then I have to close it with the presses space.
Then the backslash in a semicolon hit enter.
As we can see here, we got the keyword.
Marsh.
I can do.
I can also do it for another word.
For example, April.
I hit enter.
And as you can see, we get the same output.
Which is that one key word here, if I have the key word in a different text file.
Let's do it here, for example.
Let's see what we have.
LS L and Cat.
I will do here for the number.
So I'm going to add, for example, here, word April, for example.
Then I'm going to close this one and save the file.
So let's just check that we have here the keyword and here the month.
Okay, so we have the keywords and these two files.
So in this case, if I'm going to do the search here defined, it means that I'm going to get two outcomes
hit enter.
As we can see here, we get two.
Words of April.
Now let's move on to another command.
So another command is the same that I'm going to use the execute command.
But in this case, I would like to copy all the text files in.
So I have the first option, the type.
File, then ignore case.
It doesn't matter uppercase or lowercase.
Then between a double quotation I'm going to do star dot txt so I'm going to look for all the txt files.
Doesn't matter the name, whatever before the dot txt the extension here then e.
So I'm going to execute and I'm going to use the copy.
So what I'm going to do, I'm going to copy all the txt files in this current working directory.
To where.
To a directory under the slash home.
So here in this case, since we're going to use the.
CPP, which is the copy, then I have to use the process before the directory that I would like to.
Save all the files inside that directory, then space, then the back slash semicolon hit enter.
And dash L as we can see here now, first we have to create.
I didn't create the directory.
I'm going to create the directory here.
Making directory.
We cannot make it.
Files exist.
Okay.
Let me remove that directory.
First here.
Then I'm going to make the directory here.
Perfect.
Then I'm going to run the command again.
As we can see here, we copied all the text files to this directory.
So we're going to reboot.
So find this current current working directory and the type it's file then dash I name.
So the ignore case, it doesn't matter this between the quotation marks.
So all the text files that has the extension that the txt.
So it doesn't matter.
Ignore the names or all the names here or the numbers then since we're going to use the execute.
Copy.
So once we're going to use another command, then we have to use this.
The process we're going to use the process with the copy here.
And then after the process, we're going to use the the directory that we would like to save all those
files to this directory.
And we don't forget that we have to close the the execute command with the backslash, then a semicolon.
Let's go inside.
Okay.
LZ, Dash, L as we can see here, we have this directory.
I'm going to go inside this directory.
LZ, l as we can see here, what we did, we copied all the files from the current working directory
to this directory.
The WD.
As you can see here, we are under this current working directory.
Now let's move on to the next command.
So since I'm inside this current working directory, what I'm going to do here, I'm going to delete
all the files in this current working directory.
So WD this is the current working directory right now and find in this current working directory I name
then.
I'm going to just do the text.
So the names ignore case doesn't matter.
Upper or lower case.
Then all the.
Files that has the extension that txt then execute perfect.
R m dash rf because I would like to delete all the files in this current working directory here.
Then what I'm going to do after that?
Close the presses.
The space.
Then what I'm going to do is the backslash semicolon.
Hit, enter.
As we can see here, we don't have any file because we removed all the text files from this.
Current working directory.
If I would like to find more information about this find command, I can go to the man page.
As we can see here, we can get all the details and the options and also about this command.
As you can see over here.
The dash, execute then the command so we can get more information about how to use and also here how
to use this command with the braces.
And plus and as you can see here is that you can use it with this backslash, as we can see over here.
Hearing this if we can use the prices and with a backslash.
Okay, That's concludes our session.
Thank you and see you in the next lesson.