Giving a lot of files, sort -n
gives me this result:
f1.txt
f10.txt
f2.txt
which doesn't seem right to me. What is the explanation?
Can I get this by default:
f1.txt
f2.txt
f10.txt
osxsortterminal
Giving a lot of files, sort -n
gives me this result:
f1.txt
f10.txt
f2.txt
which doesn't seem right to me. What is the explanation?
Can I get this by default:
f1.txt
f2.txt
f10.txt
Best Answer
I recommend to use rather
-V
stands for "version sort" and it basically handles correctly both alphabetical and numerical characters, so that if you would have more files, say:then
sort -V
will give youwhereas
sort -k 1.2n
orsort -n -k 1.2
: