Click here for "Safe Air Conditioner Repair and Proper Freon Recovery".(Japanese Version)

Sorting files

Sorting files

●Sort by increasing file size.

When viewing the files in a directory, they are usually displayed in alphabetical order by file name.
However, it is possible to display the desired files and directories in size order.

In this case, you can run the ls command with the option "-S" to display the files in order of increasing file size.
The "-S" option is an uppercase S.

[root@Lion ~]# ls -l ←Display the contents of the current directory normally.
total 159480
-rw-r--r-- 1 root root 16452096 January 10 08:22 2013 custom_install.doc
-rw-rw-r-- 1 root root 40830438 January 10 08:51 2013 custom_install.pdf
-rw-rw-r-- 1 root root 66680395 January 10 08:37 2013 custom_install.ps
-rw-rw-r-- 1 root root 14745654 December 26 05:46 2012 sample.BMP
-rw-rw-r-- 1 root root 7661465 December 26 05:47 2012 sample.PNG
-rw-rw-r-- 1 root root 8353071 December 26 05:47 2012 sample.TIFF
-rw-r--r-- 1 root root 2302349 December 26 05:46 2012 sample.jpg
-rw-rw-r-- 1 root root 2971456 December 27 07:02 2012 sample_60.PNG
-rw-rw-r-- 1 root root 885383 December 27 06:56 2012 sample_60.jpg
-rw-rw-r-- 1 root root 153010 December 27 06:55 2012 sample_640x480.jpg
-rw-rw-r-- 1 root root 2242568 December 27 06:50 2012 sample_90.jpg

Sort by size.
[root@Lion ~]# ls -lS ←Displays the files in the current directory in order of size.
total 159480
-rw-rw-r-- 1 root root 66680395 January 10 08:37 2013 custom_install.ps
-rw-rw-r-- 1 root root 40830438 January 10 08:51 2013 custom_install.pdf
-rw-r--r-- 1 root root 16452096 January 10 08:22 2013 custom_install.doc
-rw-rw-r-- 1 root root 14745654 December 26 05:46 2012 sample.BMP
-rw-rw-r-- 1 root root 8353071 December 26 05:47 2012 sample.TIFF
-rw-rw-r-- 1 root root 7661465 December26 05:47 2012 sample.PNG
-rw-rw-r-- 1 root root 2971456 December 27 07:02 2012 sample_60.PNG
-rw-r--r-- 1 root root 2302349 December 26 05:46 2012 sample.jpg
-rw-rw-r-- 1 root root 2242568 December 27 06:50 2012 sample_90.jpg
-rw-rw-r-- 1 root root 885383 December 27 06:56 2012 sample_60.jpg
-rw-rw-r-- 1 root root 153010 December 27 06:55 2012 sample_640x480.jpg

●Display files in order by extension.

It may be easier to find the desired file by displaying it by extension.
By running the -ls command with the option "-X", you can display the files in order by extension.
The "-X" option is an uppercase X

[root@Lion ~]# ls -l ←Display the contents of the current directory normally.
total 159480
-rw-r--r-- 1 root root 16452096 January 10 08:22 2013 custom_install.doc
-rw-rw-r-- 1 root root 40830438 January 10 08:51 2013 custom_install.pdf
-rw-rw-r-- 1 root root 66680395 January 10 08:37 2013 custom_install.ps
-rw-rw-r-- 1 root root 14745654 December 26 05:46 2012 sample.BMP
-rw-rw-r-- 1 root root 7661465 December 26 05:47 2012 sample.PNG
-rw-rw-r-- 1 root root 8353071 December 26 05:47 2012 sample.TIFF
-rw-r--r-- 1 root root 2302349 December 26 05:46 2012 sample.jpg
-rw-rw-r-- 1 root root 2971456 December 27 07:02 2012 sample_60.PNG
-rw-rw-r-- 1 root root 885383 December 27 06:56 2012 sample_60.jpg
-rw-rw-r-- 1 root root 153010 December 27 06:55 2012 sample_640x480.jpg
-rw-rw-r-- 1 root root 2242568 December 27 06:50 2012 sample_90.jpg

Sort by extension
[root@Lion ~]# ls -lX
total 159480
-rw-rw-r-- 1 root root 14745654 December 26 05:46 2012 server.BMP
-rw-rw-r-- 1 root root 7661465 December 26 05:47 2012 server.PNG
-rw-rw-r-- 1 root root 2971456 December 27 07:02 2012 server_60.PNG
-rw-rw-r-- 1 root root 8353071 December 26 05:47 2012 server.TIFF
-rw-r--r-- 1 root root 16452096 January 10 08:22 2013 custom_install.doc
-rw-r--r-- 1 root root 2302349 December 26 05:46 2012 server.jpg
-rw-rw-r-- 1 root root 885383 December 27 06:56 2012 server_60.jpg
-rw-rw-r-- 1 root root 153010 December 27 06:55 2012 server_640x480.jpg
-rw-rw-r-- 1 root root 2242568 December 27 06:50 2012 server_90.jpg
-rw-rw-r-- 1 root root 40830438 January 10 08:51 2013 custom_install.pdf
-rw-rw-r-- 1 root root 66680395 January 10 08:37 2013 custom_install.ps

●Sort files by newest update time

Sometimes it is easier to find the desired file by displaying it in order of modification time.
In this case, you can run the ls command with the option "-t" to display the files in order of the most recent modification time.

[root@Lion ~]# ls -l ←Display the contents of the current directory normally
total 159480
-rw-r--r-- 1 root root 16452096 January 10 08:22 2013 custom_install.doc
-rw-rw-r-- 1 root root 40830438 January 10 08:51 2013 custom_install.pdf
-rw-rw-r-- 1 root root 66680395 January 10 08:37 2013 custom_install.ps
-rw-rw-r-- 1 root root 14745654 December 26 05:46 2012 sample.BMP
-rw-rw-r-- 1 root root 7661465 December 26 05:47 2012 sample.PNG
-rw-rw-r-- 1 root root 8353071 December 26 05:47 2012 sample.TIFF
-rw-r--r-- 1 root root 2302349 December 26 05:46 2012 sample.jpg
-rw-rw-r-- 1 root root 2971456 December 27 07:02 2012 sample_60.PNG
-rw-rw-r-- 1 root root 885383 December 27 06:56 2012 sample_60.jpg
-rw-rw-r-- 1 root root 153010 December 27 06:55 2012 sample_640x480.jpg
-rw-rw-r-- 1 root root 2242568 December 27 06:50 2012 sample_90.jpg

Sort by update time
[root@Lion ~]# ls -lt
total 159480
-rw-rw-r-- 1 root root 40830438 January 10 08:51 2013 custom_install.pdf
-rw-rw-r-- 1 root root 66680395 January 10 08:37 2013 custom_install.ps
-rw-r--r-- 1 root root 16452096 January 10 08:22 2013 custom_install.doc
-rw-rw-r-- 1 root root 2971456 December 27 07:02 2012 server_60.PNG
-rw-rw-r-- 1 root root 885383 December 27 06:56 2012 server_60.jpg
-rw-rw-r-- 1 root root 153010 December 27 06:55 2012 server_640x480.jpg
-rw-rw-r-- 1 root root 2242568 December 27 06:50 2012 server_90.jpg
-rw-rw-r-- 1 root root 8353071 December 26 05:47 2012 server.TIFF
-rw-rw-r-- 1 root root 7661465 December 26 05:47 2012 server.PNG
-rw-rw-r-- 1 root root 14745654 December 26 05:46 2012 server.BMP
-rw-r--r-- 1 root root 2302349 December 26 05:46 2012 server.jpg
Copied title and URL