In Linux, use find to find a file that starts with ABC but does not contain "."

Source: Internet
Author: User

 

You can use either of the following methods:

1.

  1. Find.-Name "ABC *"! -Name "*. *"-print

2.

  1. Find.-RegEx '. */ABC [^.] *'

3.

  1. Find.-Name "*. *"-o-name "ABC *"-print

The first method is the easiest to understand. It is before the second-name! It indicates-not, which has the same meaning as-not, so it can also be written:

Find.-Name "ABC *"-not-name "*. *"-print

 

Method 2: When the-name option is used, find does not support regular expressions. In this case, use the-RegEx option.

Regular Expression: '. */ABC [^.] *'

. */Indicates searching in the current directory and Directory

[^.] * Indicates that ABC matches any character,.

 

The third method seems hard to understand

Because-O means or, that is, or

It seems like finding all the records that contain or start with ABC

Otherwise

These two-names constitute an expression in this form.

Exp1 or exp2

If exp1 is true, it will not be judged again

If exp1 is false, execute exp2, which is very similar to the "|" symbol in C.

Therefore, if a file with a. Name is matched, it will not be followed, so-print will not print at this time.

 

I also accidentally discovered a point today.

Find [path...] [expression]

-Exec command can be used at the end

As follows:

Find.-Name "ABC *"-exec ls {}/;

I have never understood what to add {}/;

I finally got it today.

In fact, {} indicates matching the previous file.

Therefore, you can also use:

Find.-Name "ABC *"-exec MV {}{}. Old /;

The completed functions are as follows:

Add the. Old suffix to all files switched with ABC

 

(Thank you very much for your guidance)

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.