Notes on the find command in Linux

Source: Internet
Author: User
Notes on the find command in Linux-general Linux technology-Linux programming and kernel information. I don't catch a cold on becoming a linux system administrator, but who makes me a serious interest-oriented plus breadth-oriented learning.

From the first day of access to linux, I need the find command, for example, looking for the damn ones. c ,. where is the H file, or a configuration file. where are etc and so on. Compared with windows Search, the find command is a little troublesome. To complete a specific task, you have to think a lot about it, and man find is so disgusting that you cannot understand it. Just touch the stones and cross the river. Take it easy.

Example 1:
For example, if you want to find all *. file files in a directory, but want to skip the test1 subdirectory, test2 subdirectory, test3 ......

OK

& Sudo find. \ (-path ". /test1 "-o-path ". /test2 "-o path ". /test3 "....... -o path ". /testX "\)-prune
-O-type f-name "*. file"-print

How long is it?

Okay. Let's explain it at 1.1.

First, sudo skips. Then, find skips.

Then, a "." can be omitted to indicate the current directory.

Next, "\ (" and "\)" appear in pairs. Here "()" indicates that shell does not explain the things in parentheses, give it to the find command for explanation. Well, that's exactly what it said. I don't know the specifics, especially what it is called "shell doesn't explain, just give it to find to explain". Whatever it is, just write it.

Note that there must be spaces before and after "\ (" and "\)". Otherwise, an error may occur. \ (-path "is not allowed and must contain spaces.

-Path "path"

Here, each-path corresponds to a subdirectory that you want to ignore, and there must be spaces behind-path, which cannot keep up with the directory.

Single quotes and double quotes do not matter. One is a strong quote and the other is a weak quote. The difference is certainly there, but it has not been understood yet.

Each-path "path" is followed by a-o representation-or a string of paths connected with this-o

Then the-prune option, which means "cut down"

Another-o will be explained later.

The following is more common. Select the file type with "*. file" as the file name. Note that the double quotation marks can be omitted here (alas, leave this double quotation mark alone and stay dizzy here)

Okay, the key is-o

In fact, a bunch of-a "-and" are omitted"

Meaning:

If
. \ (-Path ". /test1 "-o-path ". /test2 "-o path ". /test3 "....... -o path ". /testX "\) created

Then execute prune

Otherwise, execute
-Type f-name "*. file"-print

Where
. \ (-Path ". /test1 "-o-path ". /test2 "-o path ". /test3 "....... -o path ". /testX "\)

Indicates that the directory under the current directory meets./test1 or./test2 or...-You know why-o is used.

Note: "./" in "./test" cannot be saved. Be sure to specify it.

Otherwise

You can think like this, although somewhat far-fetched

Find is followed by a bunch of directories, and then an action, for example,-prune is cut,-print is printed to the console

-O indicates that the selection can be understood as the if else statement. If-o is not added, it indicates that-a is executed together.

If (a bunch of directories)
Action 1...
Else
Action 2...
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.