简体   繁体   中英

What's the wildcard for dot in bash?

I have files like 0001.file1.email.data.spam.txt and 0001.file1.email.data.spam_1.txt

Now I want to delete all files end with "_1.txt", I tried to use "rm -rf *spam_1.txt", but it cannot find the files. Maybe because * cannot viewed as dot.

Dot is a literal character which simply matches itself.

The * wildcard matches any sequence of characters, and the ? wildcard matches any single character, but wildcard matching will ignore files which start with a dot unless you have dotglob enabled (it is off by default).

You can easily examine what files are being matched by a wildcard expression with something like

printf '>>%s<<\n' *spam_1.txt

(The >> ... << decoration is just to make it easy to see any leading or trailing whitespace, and isn't strictly necessary.)

In the absence of nullglob , the above will print the wildcard itself if it doesn't find any matches. Also check out failglob which causes an error to be printed and the command to be aborted if the wildcard doesn't match anything.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM