2

This question already has an answer here:

Here is the output of my normal ls command:

f1  f10  f11  f12  f13  f14  f15  f16  f17  f18  f19  f2  f20  f3  f4  f5  f6  f7  f8  f9

So I have 20 files. I need them displayed as :

f1  f2 f3  f4  f5  f6  f7  f8  f9 f10  f11  f12  f13  f14  f15  f16  f17  f18  f19  f20  

Is there any single-line command to this other than writing a script? I am sure some of you must have faced this weird situation. Note: the above is just a sample. In the actual scenario I need a list of all the file names in proper sorted order. (ranging from f{0..10000})

marked as duplicate by don_crissti, cuonglm, Jeff Schaller, Stephen Kitt, Jenny D Mar 9 '16 at 16:26

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

fortunately! there is a single-line command

ls -lav

should do what you are looking for

  • Oh Natural sort! cool. – 0aslam0 Mar 9 '16 at 14:21
2

With GNU ls, you can use:

ls -v

With POSIX tools chest:

ls | sort -nk1.2 | paste -sd ' ' -

If you are sure that all files in range existed, with shells have brace expansion:

echo f{1..20}

With zsh:

print -r -- f*(n)

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