Linux wildcard characters, metacharacters, and special characters

Source: Internet
Author: User

Features that are useful in bash environments: wildcards, escape characters, and special characters are described below


One, wildcard characters

A wildcard is a special statement that has an asterisk (*), a question mark (?). And so on, used to blur the search file, when looking for a directory or file, you can use wildcard characters instead of one or more true positive characters.

Scope: directory and file name

Common wildcard characters: Common wildcard characters include "*", "?", "[]", "[^]", "[!]" and "{}", the specific meaning is shown in the following table

Table 1-1 the specific meanings and usage tables of the wildcard characters

Character Meaning
* Horse character with any word
Match a single character
[] Matches any one of the square brackets and cannot be used to create directories and files
[^] Match any one of the characters or numbers in the square brackets and reverse them, equivalent to [! ], indicating that the range can be used with ".." or "-" to find and delete directories and files without creating directories and files
[!] Match any one of the characters or numbers in the square brackets after the inverse, equivalent to [^], indicating that the range can be used "..." or "-" to find and delete directories and files without creating directories and files
[? -? ] Matches any one of the brackets in the range, for querying, deleting, but not for creating directories and files
{string,string} Matches any one of the strings in parentheses, representing a range, between strings "..."

specific usage one by one illustration

    • Root creates directories F1 and F2 at once, and now requires a one-time removal of F1 and F2 files via wildcard characters

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M00/9B/92/wKioL1lkkvaSMiWCAAAe-PdWPOA008.png "title=" Ls.png "alt=" Wkiol1lkkvasmiwcaaae-pdwpoa008.png "/>

    • Root created F1 to F9, now requires a one-time wildcard creation and removes F5 to F8

Error usage 1: Use square brackets to create a F1 to F9 directory,

650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M02/9B/97/wKiom1lkvKeQIbPTAAAQ0TVgf2s633.png "title=" Ls.png "alt=" Wkiom1lkvkeqibptaaaq0tvgf2s633.png "/>

Error usage 2: Use curly braces-to represent a range to create a directory F1 to F9

650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M02/9B/97/wKiom1lkvVTDgfg0AAARBTrU2eo306.png "title=" Ls.png "alt=" Wkiom1lkvvtdgfg0aaarbtru2eo306.png "/>

to create a directory correct practice: The correct approach is to use braces, scope with ".." Represents

650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M00/9B/97/wKioL1lkvaXRwkK9AAA8ys9wbeg311.png "title=" Ls.png "alt=" Wkiol1lkvaxrwkk9aaa8ys9wbeg311.png "/>

Delete directory One of the correct methods: use [^] or [!] to Undelete

650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M00/9B/97/wKiom1lkwbDj7e5aAAAkqYR9kwU316.png "title=" Ls.png "alt=" Wkiom1lkwbdj7e5aaaakqyr9kwu316.png "/>


Two, meta characters

Metacharacters: The shell is responsible for interpreting the processing, and special characters have special meanings.

Character Meaning
= Set variables, function assignments, etc.
$ Replace as a variable or operation
> or " REDIRECT StdOut
< or the REDIRECT StdIn
& The 2>1& translates the standard error output to the standard correct output, 1>2$ the standard positive output to the standard error output &> positive fetch error Output
( ) Combining $ () with "$ ()" To implement command invocation, the parentheses in the synthetic operation are preferred
{} Scope defined, such as for I in {1..10}, variable I value range 1 to 10
; Semicolon, multiple commands are executed in turn, the execution process is not dependent
&& Previous command execution feedback is correct, that is $?=0, continue to execute next command
|| The previous command performs a feedback error, that is, $?=1, and then proceeds to the next command
! and ~

! Reference history statement, ~ is home directory

To illustrate:

    • View/app/hellohh and/app directory files with LS and redirect to 1.log file for problem analysis

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M00/9B/9D/wKioL1llZMKxVE6yAAA8IJoEbes791.png "title=" Ls.png "alt=" Wkiol1llzmkxve6yaaa8ijoebes791.png "/>

redirect both correct and incorrect standard output through &>


Three, escape character

escape character: The character meaning of the wildcard character and the metacharacters into itself

Character Meaning
‘ ’ Hard escaping, comparing silly character references, preserving the original character meaning, not escaping
" " Soft escaping, escaping special characters into characters with special meanings
$ () equivalent to ' Force Reference Command,
\ Display the original special character

specific examples are as follows:

    • Define alias Baketc, daily manual Regular backup of all files in/etc directory, backup to/testdir Independent subdirectory, and require subdirectory format BAKUPYYYY-MM-DD, backup process visible (strong reference ")

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M01/9B/9B/wKiom1lk3weQyxZLAAAMx6df9Zs646.png "title=" Ls.png "alt=" Wkiom1lk3weqyxzlaaamx6df9zs646.png "/>

    • Add user bash, Testbash, basher, SH, nologin (shell is/sbin/nologin), find the/etc/passwd file, the user name and the shell name of the row

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M01/9B/9B/wKioL1lk4fOAW22VAAAdbpvKmlc850.png "title=" Ls.png "alt=" Wkiol1lk4foaw22vaaadbpvkmlc850.png "/>

WHERE. * The first \ is the escape character, which represents the string ending with/string$

    • After configuring the NIC information, the IP configuration error is found, so the NIC information is reconfigured using the history command.

650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M00/9B/9B/wKiom1lk4xaAf2QEAAASR-A_4Ds957.png "title=" Ls.png "alt=" Wkiom1lk4xaaf2qeaaasr-a_4ds957.png "/>


####################################################################################

### For details, please contact: QQ767743577 e-mail address: [email protected], have asked to answer, there is Bing, everyone for me, I for everyone ###

####################################################################################

This article is from the "11831715" blog, please be sure to keep this source http://11841715.blog.51cto.com/11831715/1946848

Linux wildcard characters, metacharacters, and special characters

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.