I want to concatenate a bunch of files together in filename order.
Is it safe to assume that this will give me them in alphanumeric order?
i.e. the same order that
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
Short answer: Yes it will.
From the bash man page:
After word splitting, unless the -f option has been set (see The Set Builtin), Bash scans each word for the characters ‘*’, ‘?’, and ‘[’. If one of these characters appears, then the word is regarded as a pattern, and replaced with an alphabetically sorted list of file names matching the pattern.
The short answer is yes, but you need to be aware of what it thinks the alphanumeric order should be, as it may not correspond to the natural order you have in mind.
For example, run some test on how upper and lower case are handled to find out on your system, as well as sequences of numbers.
A common problem I have run into in ordering lists of files returned by a glob is numbered files. I am often given files numbered like:
blah_1.txt blah_2.txt ... blah_10.txt blah_11.txt
However, a glob using the
* will not return them in this order, instead you will get something like:
blah_1.txt blah_10.txt blah_11.txt ... blah_2.txt blah_20.txt ...
So - to avoid this problem you'll either need to do some manipulation on the returned list of files, or rename files so that single digits have leading zero (i.e.