14

What is the meaning of following ls command?

ls -l *\:2,*T
  • ls = list
  • -l = long (list)
  • *T probably means T at the end

But what about that *\:2 and the comma?

3 Answers 3

25

*\:2,*T is the glob pattern of files to list. To understand it, we need to remember a few things:

  • : has to be escaped in the shell, becoming \:
  • File names can easily contain commas

So *\:2,*T would e.g. match a file called TranscationNumber:2,EventType:XYT

EDIT

From the comments, the necessity (or not) of escaping the : needs a few words: It is not strictly necessary to escape the : sign, but bash itself suggests it when autocompleting.

9
  • 3
    Thank you, both Eugen and HBruijn. I suspected some complicated globbing pattern, but actually it should just match the colon and the comma, which I did not think of when working with files. Now, the command totally makes sense: list all email files in the Maildir directories, which are marked as "Deleted" (T). Btw. The number 2 means Maildir in version 2 (cf wiki2.dovecot.org/MailboxFormat/Maildir). Aug 18, 2017 at 11:20
  • 11
    Since when does : have to be escaped?
    – Barmar
    Aug 18, 2017 at 17:48
  • 7
    : doesn't need to be escaped. It is only special in specific circumstances (when used as a command), not in glob patterns. The \: is equivalent to :, escaping makes no difference.
    – terdon
    Aug 18, 2017 at 18:11
  • 1
    @Aaron, it's not exactly no-op: the shell will still process variable substitutions, particularly the assignment variety (i.e. to set default values): unset var; : ${var:=x}; echo $var Aug 19, 2017 at 13:23
  • 3
    @terdon & @Aaron The colon : is part of the default values for the COMP_WORDBREAKS environment variable. In Bash autocompletion those characters are used as word separators by the read line library and a file-name containing a colon should of course be a single word. Hence the reason that bash autocompletion requires the colon to be escaped, although otherwise it is "mostly" not a special character...
    – HBruijn
    Aug 23, 2017 at 7:49
14

List all files that match the wildcard pattern *:2,*T

There the wildcard * matches anything (any number of all possible characters)
:2, are characters that need to be present in the file/directory names.
The colon : is a special character that needs to be escaped, hence the form of \:2,.
The file/directory names need to end with a T.

File names that would match would be

:2,T
a:2,T
a:2,bT
abbY-$fafaf:2,<hskjhsgdfhjk>T
2
  • 1
    There's nothing special about :, it doesn't need to be escaped.
    – Kevin
    Aug 18, 2017 at 19:05
  • @Kevin bash auto-completion automatically escapes the colon in file/directory name patterns, because is included in the list of COMP_WORDBREAK environment values that get set by default. - So it is indeed not an actual special character, but when you use autocompletion on the commandline and want/need to match filenames with a colon , it does need to be escaped.
    – HBruijn
    Aug 23, 2017 at 7:39
9

As others have noted, this will list in long format, files containing :2, and ending in T

This looks like a search in a Maildir folder for files that were deleted (trashed). However, for robustness it should have had another * at the end, though. New flags with a later alphabetical position could be added, and Dovecot for instance adds another field with the file size at the end.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .