Linux filename matching (wildcard usage) __linux

Source: Internet
Author: User

When using the command line, there is a lot of time to find the files you need, such as LS found. S H e l L provides a complete set of string pattern matching rules, or as a meta character, when S H e l L encounters these characters, they are treated as special characters instead of ordinary characters in the file name, so that they can be used to match the corresponding file names, which I understand to be called wildcard characters.

Wildcard characters are different from regular expressions, in a nutshell: Wildcards are used to match strings, and regular expressions are used for string literals, and in text filtering tools, regular expressions, such as awk,sed, and so on, are intended for the contents of a file. Wildcard characters are used in file names, such as looking for FIND,LS,CP, and so on. Second, the Shell's wildcard character differs from the regular expression, and the "" is generally a wildcard (the shell itself is extracted), and "is generally a regular expression (the shell passes data from it to other commands)."

The following are the common wildcard characters:

* matches any string in the filename, including an empty string.

。 Matches any single character in the file name.

[...] Matches any character contained in [].

[!...] Match [] non-exclamation point. After the characters.

Such as:

All strings beginning with 5* 5

All strings at the end of *5 5

*5. A string with 5 as the penultimate character

[0-9] All with a number of characters

[1,2] 1 or 2

[!0-9] is not a character of a number

ls/etc/[!a-n]*.conf lists files in the/etc/directory that do not start with the letter A through n, and end with. conf

ls/etc/[a-n]*.conf lists files that start with the letter A through n in the/etc/directory and end With. conf

ls/bin/[ck]* lists filenames that start with C or K

If there are any irregularities, please correct me.

Reference: http://bbs.lupaworld.com/thread-38881-1-1.html

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.