Linux Shell wildcard character (globbing)

Source: Internet
Author: User


A wildcard is handled by the shell, and it appears only in the parameters of the command (it is not used in the command name or on the operator). When the shell encounters a wildcard in parameters, the shell treats it as a path or file name to search for possible matches on the disk: If a matching match exists, the substitution (path extension) is performed, otherwise the wildcard is passed as a normal character to the command, which is then processed by the command. In short, a wildcard is actually a kind of path extension that the shell implements. After the wildcard is processed, the shell completes the reorganization of the command before continuing with the reorganized command until the command is executed.

Shell Common wildcard characters:

Character

Meaning

Instance

*

Match 0 or more characters

A*b A and B can have any character of any length, or there can be none, such as AABCB, AXYZB, a012b, AB.

?

Match any one character

A?b A and B must also have only one character, which can be any character, such as AAB, ABB, ACB, a0b.

[List]

Match any single character in the list

Note: Notes record several special single symbol representations.

A[xyz]b A and B must also have only one character, but only x or Y or Z, such as: AXB, Ayb, Azb.

a[[:upper:]]b   There are and Span style= "Font-family:tahoma;color:rgb (68,68,68); letter-spacing:0;font-size:12px;" > uppercase character

[!list] or [^list]

Matches any single character except the list

a[ 0-9]b  a and B must also have only one character,  but not Arabic numerals,  such as axb, aab, a-b.

[C1-C2]

 

Match any single word in c1-c2 such as: [0-9] [A-z]

A[0-9]b 0 and 9 must also have only one word such as a0b, a1b ... a9b.

Note: Several common special symbols are indicated:

 [[:lower:]]: All lowercase letters

 [[: Alpha:]]: All letters

 [[: Alnum:]]: All letters and numbers

 [[:space:]]: all whitespace characters

 [[: Punct:]]: All punctuation

It is necessary to note that the wildcard looks a bit like a regular expression statement, but unlike regular expressions, it cannot be confused with each other. The wildcard character can be interpreted as a shell special code. And the only thing involved is *,? ,[] these kinds.

Comprehensive example Applications:

1: Displays all files or directories with an L, ending with a lowercase letter, with an arbitrary character in the middle of the/var directory;

Ls-d/var/l? [[: Lower:]]

2: Displays a file or directory that starts with any digit in the/etc directory and ends in a non-numeric number;

Ls-d/etc/[0-9]*[^0-9]

3: Display in/etc directory, starting with a non-letter, followed by a letter and any other arbitrary length of any character file or directory;

Ls-d/etc/[^a-z][a-z]*

4: Copy/etc directory, all files or directories ending with. conf and beginning with m,n,r,p to the/tmp/conf.d/directory;

Cp-r/etc/[mnrp]*.conf/tmp/conf.d/


This article is from the "home of small Mosquitoes" blog, be sure to keep this source http://timber.blog.51cto.com/7677013/1725215

Linux Shell wildcard character (globbing)

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.