Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to order ls command display in numerical order?

Tags:

bash

ls

I created 3 files in a directory with the following names:

11 13 9

Problem, as I created file 9 after 13 it is placed after file 13 when I do the ls command.

Do you have any idea to make the ls command sort the files in the numerical order, like this:

9 11 13

like image 335
george Avatar asked Sep 16 '16 10:09

george


People also ask

How do you order ls?

In order to ls by date or list Unix files in last modifed date order use the -t flag which is for 'time last modified'. or to ls by date in reverse date order use the -t flag as before but this time with the -r flag which is for 'reverse'.

What order does ls print in?

As we already mentioned, by default, the ls command is listing the files in alphabetical order.

How do you sort ls in terminal?

ls command sort by time with -lht options in Linux The best way to sort by time in Linux ls command is using ls with -lht options. Open the terminal and type ls -lht. The most recently modified file will be listed on the first. The output is in the long format and the file size is in human readable format.

How do I sort numbers in Linux?

To sort by number pass the -n option to sort . This will sort from lowest number to highest number and write the result to standard output. Suppose a file exists with a list of items of clothing that has a number at the start of the line and needs to be sorted numerically.


1 Answers

Look at the man page for ls. From there-

-v natural sort of (version) numbers within text.

You'll find that the command ls -v does what you want.

If you want the file names on different lines then you can do ls -1v.

like image 94
Chem-man17 Avatar answered Nov 08 '22 12:11

Chem-man17