1

Let's say that I have 3 files in a directory:

apple.txt:

apple

beehive.txt:

beehive

zebra.txt:

zebra

If I concatenate this files with:

cat *.txt > all_files.txt

I do get:

apple
beehive
zebra

(I tested it on 5 files too, and I get the same behavior),

But my is this behavior guaranteed?

marked as duplicate by Julie Pelletier, sam, mdpc, icarus, Mongrel Feb 2 '17 at 2:24

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

4

From the POSIX shell specification of Filename Expansion

If the pattern matches any existing filenames or pathnames, the pattern shall be replaced with those filenames and pathnames, sorted according to the collating sequence in effect in the current locale.

So unless you have an unusual collation sequence in your locale, you can depend on it being alphabetical.

  • 1
    Nitpick: Lexicographical. – Kusalananda Feb 1 '17 at 21:00
  • @Kusalananda If the names only contains letters, as in the example in the question, alphabetical == lexicographical. – Barmar Feb 1 '17 at 21:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.