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

Time:11-18

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?

CodePudding user response:

"[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.

CodePudding user response:

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.
  • Related