Regular expressions and special symbols in the shell

Source: Internet
Author: User

There is also a very useful feature in Bash's operating environment, which is the wildcard character (wildcard)! It's even easier for us to use bash to process data! Below we list some commonly used wildcard Fu Yi:

Symbol Significance
* Represents "0 to infinity" of any character
? Represents "must have a" any character
[ ] Also means "there must be a character in parentheses" (not any character). For example [ABCD] represents "must have a character, may be a, B, C, d these four any one"
[ - ] If a minus sign is inside the brackets, it represents "all characters in the code order." For example [0-9] represents all numbers between 0 and 9, because the language encoding of the numbers is continuous!
[^ ] If the first character in the brackets is an exponential sign (^), that means "invert selection", for example [^ABC] means that there must be a character, as long as the other characters of non-A, B, C are accepted.

Let's use the wildcard characters to play something now! First, use the wildcard character with the LS file name to see:

[[email protected] ~]# lang=c              <== because of the encoding, first configure the language example one: Find out the/etc/under the cron-beginning file name [[email protected] ~]# ll-d/etc/cron*    <== Plus-D is to show only the table of contents. Example two: Find the file name "exactly five letters" under/etc/[[email protected] ~]# ll-d/etc/?????    <== because? There must be one, so five of them? That's right. Example three: Find out the file name of the/etc/under the name of the file containing the numbers [[email protected] ~]# ll-d/etc/*[0-9]*  <== Remember that both sides of the brackets need * Example four: Find the/etc/under, File name starts with a file name that is not a lowercase letter: [[email protected] ~]# ll-d/etc/[^a-z]*  <== Note the left side of the brackets is not * Example five: Copy the files found in sample four into/TMP [[email protected] ~]# cp-a/etc/[^a-z]*/tmp

In addition to wildcards, what are the special symbols in the bash environment? We'll take a look at the bottom:

Symbol Content
# notation: This is most commonly used in script, as a description! None of the data is running after
\ Skip symbol: Revert a "special character or wildcard" to a normal character
| Pipeline (pipe): Delimited two pipeline command definition (the latter two sections are introduced);
; Continuous command Release delimiter: definition of continuity command (note!) Not the same as the pipeline command)
~ User's home directory
$ Take the variable leader: that is, the variable that needs to be added before the variable to replace the value
& Job Control: Turn the command into a background job
! The meaning of "not" in the sense of logical operation!
/ Directory symbols: path-delimited symbols
, >> Data flow redirection: output-oriented, "replace" and "accumulate", respectively
<, << Data flow redirection: Input orientation (these two are for the next section)
‘ ‘ Single quotes, no function of variable substitution
" " function with variable substitution!
` ` Two "'" in the middle of the command can be run first, also use $ ()
( ) The beginning and end of the child shell in the middle
{ } In the middle for a combination of command blocks!

These are the special symbol sinks that are common in bash environments! Theoretically, your "file name" try not to use the above characters!

Regular expressions and special symbols in the shell

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.