Linux\mac Daily Entry command line use--Search files \ Folders

Source: Internet
Author: User

Searching for files or folders is a common requirement. We can use a variety of commands to achieve our needs.

Find Command Implementation Search

findIt'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"
    • 1

Directory parameter keywords for command search

-inameis 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. grepThe command can also be filtered by keyword. Then we can combine this command.

| grep txt
    • 1

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
    • 1
    • 2

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.