Shell Programming (iv) globbing

Source: Internet
Author: User

Globbing: File name wildcard (whole file name match, not part)


Match pattern: metacharacters

*: matches any character of any length

pa*, *pa*, *pa, *p*a*

PA, PAA, passwd

?: matches any single character

Pa??? PA, P?a, P?a?

PA, PAA, passwd

[]: matches any single character within the specified range

There are several special formats:

[A-z], [A-z], [0-9], [a-z0-9]

[[: Upper:]]: All uppercase letters

[[: Lower:]]: All lowercase letters

[[: Alpha:]]: All letters

[[:d Igit:]]: All numbers

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

[[: Space:]]: all whitespace characters

[[:p UNCT:]]: All punctuation

PA[0-9][0-9], 2[0-9][0-9]

[^]: matches any single character outside the specified range

[^[:upper:]]

[^0-9]

[^[:alnum:]]


Exercise 1: Show all files or directories in the/var directory that start with L, end with a lowercase letter, and appear in the middle of an arbitrary character;

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


Exercise 2: Display 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]


Exercise 3: Display a file or directory that starts with a non-letter, followed by a letter and any character of any length, in the/etc directory;

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


Exercise 4: Copy all files or directories that start with M and that end with a non-digit to the/tmp/magedu.com directory, in the/etc directory;

Cp-r/etc/m*[^0-9]/tmp/magedu.com/


Exercise 5: Copy the/usr/share/man directory, all the files or directories that begin with man, followed by a number, to the/tmp/man/directory;

Cp-r/usr/share/man/man[0-9]/tmp/man/


Exercise 6: Copy all files or directories that end with. conf and start with m,n,r,p in the/etc directory to the/tmp/conf.d/directory;

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


Shell Programming (iv) 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.