简体   繁体   中英

I don't understand the meaning of ls [aDt]*t?t

Probably a quick and easy one for you guys but I can't actually find an answer anywhere.

What does this mean? Break it down for me, please?

The naswer is simple:

  • [aDt] : the character a or D or t .
  • * : zero or more (any) characters.
  • . : the dot.
  • t : the t character.
  • ? : any (single) character.
  • t : the t character.

"[aDt]*.t?t" is an expression of the "shell expansion" (there are several types, this one is "pattern matching").

This expansions use wildcard-type items to match not only a single name, but multiple.

In the case of ls command (your question, but the same applies to any command), it will list all the files having a matching name, but not other files.

[aDt]  matches any of the character "a", "D", "t"
*      matches any number (even zero) of any character
?      matches any single character

This expression can match, for example

  D-data.txt
  a-what.tNt
  t.tst

but not

  mega.txt      (first letter is not a, D or t)
  ciao.TXT      (the uppercase T of TXT do not match)
  ciaotxt       (does not contain a dot)

This is only a partial reply, things are much more complicated.

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