Problem: A log directory with a lot of 00, 01, 02 ... 31 's Date directory, how to list all directories between 00 and 12th numbers. That is, how to use the regular on top of the file name.
Shopt (shell option so understand easy to remember)
$ shopt autocd off cdable_vars off Cdspell off Checkhash off Checkjobs Off Checkwinsize on Cmdhist on compat31 out compat32 off COMPAT40 off compat41 Off Compat42 off Complete_fullquote on Direxpand out Dirspell off Dotglob off Execfail Off expand_aliases on Extdebug out Extglob on Extquote on Failglob off Force_fignore o N Globstar off globasciiranges off gnu_errfmt out histappend on Histreedit off histverify off H Ostcomplete off Huponexit off interactive_comments on lastpipe off lithist off Login_shell Off Mailwarn off no_empty_cmd_completion off Nocaseglob out nocasematch off Nullglob off Progcomp On Promptvars on Restricted_shell off shift_verbose out SourcePath on Xpg_echo off
Only one configuration item is mentioned here: Extglob
Regular
shopt-u extglob #关闭bash recognition of shopt-s Extglob #打开bash recognition
After opening, the following 5 pattern matching operators will be recognized:
? (pattern-list) #所给模式匹配0次或1次
* (pattern-list) #所给模式匹配0次以上包括0次
+ (pattern-list) #所给模式匹配1次以上包括1次
@ ( pattern-list) #所给模式仅仅匹配1次
! ( pattern-list) #不匹配括号内的所给模式
Problem Resolution: How to List all directories between 00 and 12th.
Ls-al + (0[0-9]|1[0-2])
Description
At ordinary times, the wildcard character of the shell is just the wildcard semantics, not the regular semantics
After adding this extglob, the ability is the regular semantics
Syntax format is + regular