The glob of the characteristics of Linux_bash

Source: Internet
Author: User
Tags glob

What is Glob? Glob is the file name of the wildcard mechanism, so that document management is more convenient, concise, fast; When you manage files in the future, you can perform a one-time operation, which can quickly improve the work task!

To implement the file name wildcard mechanism, you need to use the meta characters in the match. Write matching pattern (pattern) based on meta-characters

The meta characters in the Glob are as follows, and are some of the characters that people often use.

1, *: Match any character of any length;

Example: p* all files starting with lowercase p (note case sensitive)

pa* all files that begin with a lowercase PA

*p*a the letter p is preceded by multiple or an arbitrary character, and the letter P and a have multiple or an arbitrary character. Example: Qw1p23rta, wp0a, Ppaa ... Wait a minute

2,? : matches any single character;

Example: P? Start with P, followed by an arbitrary character.

such as: PA, Po, p1 is correct, whereas PAA, p2w can not;

P? A begins with P, the small a ends, and the middle can be any single character;

such as: P1a, PWA, POA

P?? Start with P, followed by two arbitrary characters;

such as: PAA, P21, p31

Simply put, there are a few "? ", there are several characters. And the position of the character with "? As

3, []: matches any single character within the specified set;

such as: (1), [ABC], the file contains "a" or "B" or "C" file; Example: Fstab, IFCONFG, passwd, etc.

(2), p[abc]*, the file is displayed "Pa" or "PB" or "PC" file, such as: passwd, Pam, PBC, PB2Q3, Pc3.txt and so on. (Note: Some file names are randomly written, not present in the computer)

(3), if you want to show all the letters, it can be expressed as [A-z] or [a-z]; that is, p[a-z]*=p[a-z]. (Note: Character case insensitive)

(4), if the number is to be expressed, it can be expressed as [0-9];

(5), if you want to represent numbers, letters, it can be expressed as [a-z0-9]. Note: Two consecutive hyphens indicate that a collection is also possible.

(6), if you want to indicate uppercase letters, it can be expressed as [[: Upper:]]. Note: [: upper:]=a-z;[[:upper:]]=[a-z]. Example: p[[:upper:]]*, which means that p must be followed by a single character with uppercase letters, such as PM, PA, and so on.

(7), if you want to indicate lowercase letters, it can be expressed as [[: Lower]]. Usage and [[: Upper]], please be aware!

(8), if you want to represent all the numbers, it can be expressed as [[:d ight:]]

(9), if you want to show all the letters, regardless of the case. can be expressed as [[: Alpha:]]. The 2nd above already mentions one, this is the second way of expression, please know!

(10), if you want to represent all letters, numbers, it can be expressed as [[: Alnum:]];

(11), the expression of all white space characters, can be used [[: Space:]] to indicate;

(12), the expression of all punctuation marks, [[:p UNCT]] can be expressed;

4, [^]: matches any character outside the specified set;

such as: (1), if you want to take a character other than all letters, it can be expressed as [^[:alpha]]; For example: p[^[:upper:]]*, you can indicate that the file has Popd.d, P26, P2k.txt, Pp.pdf, Psswad and so on.


I did not learn Linux for a long time, or in a small white state! This is the first time to write a blog, not written please forgive. If there are mistakes or better suggestions, hope to teach. Thank you!

Please be aware!

This article is from the "11265133" blog, please be sure to keep this source http://11275133.blog.51cto.com/11265133/1747928

The glob of the characteristics of Linux_bash

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.