How to list all files sorted by size in Linux

In this short article, we will provide a lot of useful options ls command to list all files in a specific directory by file size and sort them in Linux.

To list all files in a directory, open a terminal window and run the following command. Please note that when you call ls without any parameters, it will list the files in the current working directory.

In the following command, -l flag indicates that the long format, displaying the content list directory. Information from left to right in order of output, including file name, file type, permissions mode, hard links, owner, group.

And tell ls -a list all files, including (.) Or hidden files.

[Linuxmi Linux @: ~ / www.linuxmi.com] $ ls -la

How to list all files sorted by size in Linux

or

[Linuxmi @ linux: ~] $ ls -la /home/linuxmi/www.linuxmi.com/

How to list all files sorted by size in Linux

To list all files and press the size of the sort, use the -S option. By default, it displays the output (descending) in descending order.

[Linuxmi @ linux: ~] $ ls -laS /home/linuxmi/www.linuxmi.com/

How to list all files sorted by size in Linux

You can add -h option, user-friendly format to output file size, as shown.

 [Linuxmi @ linux: ~] $ ls -laSh /home/linuxmi/www.linuxmi.com/

How to list all files sorted by size in Linux

And reverse sorted order, add -r flag, as shown in FIG.

[Linuxmi @ linux: ~] $ ls -laShr /home/linuxmi/www.linuxmi.com/

How to list all files sorted by size in Linux

In addition, you can use the -R option recursively list subdirectories.

[Linuxmi @ linux: ~] $ ls -laShR /home/linuxmi/www.linuxmi.com/

How to list all files sorted by size in Linux

If you list the Linux sorted by file size in other ways, please leave a message below column to share with us?

Guess you like

Origin www.linuxidc.com/Linux/2020-02/162369.htm