Searching for files or folders is a common requirement. We can use a variety of commands to achieve our needs.
Find Command Implementation Search
find
It's English, look for the meaning. This command can be very helpful in searching for what we need.
The standard commands are as follows:
./ -iname "*.txt"
Directory parameter keywords for command search
-iname
is case insensitive. If you want to be case sensitive, you -name
can. In general, our search content is case insensitive.
Keywords can be used *
to make a wildcard. In fact, regular expressions are also supported. But I guess you may not be familiar with regular expressions, so don't force them.
This is standard usage. But I'm going to recommend the use of a combination command I like next.
Find + grep Search
The default find
command, function and its powerful, and the most basic also need to know one *
such wildcard. But with this combination command, you can make any search that you don't know anything about.
We know the find ./
command to list all the contents of the current folder. grep
The command can also be filtered by keyword. Then we can combine this command.
| grep txt
This command allows you to list all the names contained in the current directory txt
.
In addition, we can combine multiple keywords for further filtering, as long as you follow the input | grep 关键词
.
Most importantly, it can be reversed, that is, grep
add -v
this parameter.
Examples are as follows:
grep txt | grep Sitefind ./ | grep txt | grep Site | grep -v linux
Look, it's important that we can do whatever we want without having to take care of what the regular, what wildcard, and our simple combination command.
|
Is the meaning of the pipe. The function is to pass the result of the previous command to the subsequent command to continue execution. This is a very important and useful concept in the command line. We can use these to do a lot of combination operations.
Yes, I remember when I finished, we don't have to use find ./
it as the first command, and we can use it find .
as a command. The effect is the same. Hey.
This article by Fungleo Original, allow reprint, but reprint must retain the initial link.
Linux\mac Daily Entry command line use--Search files \ Folders