Linux show all files by size

How to List All Files Ordered by Size in Linux

In one of our several articles about listing files using the popular ls command, we covered how to list and sort files by last modification time (date and time) in Linux. In this short handy article, we will present a number of useful ls command options to list all of the files in a certain directory and sort them by file size in Linux.

To list all files in a directory, open a terminal window and run the following command. Note that when ls invoked without any arguments, it will list the files in the current working directory.

In the following command the -l flag means long listing and -a tells ls to list all files including (.) or hidden files. To avoid showing the . and .. files, use the -A option instead of -a .

List All Files in Linux

To list all files and sort them by size, use the -S option. By default, it displays output in descending order (biggest to smallest in size).

List All Files Sort By Sizes

You can output the file sizes in human-readable format by adding the -h option as shown.

List Files Sort By Sizes in Linux

And to sort in reverse order, add the -r flag as follows.

List All Files Sort By Sizes in Reverse Order

Besides, you can list subdirectories recursively using the -R option.

List Sub-directories Recursively

You will also find the following related articles useful:

If you any other way to list the files ordered by sizes in Linux, do share with us or do you have questions or thoughts to share about this guide? If yes, reach us via the feedback form below.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

Читайте также:  Windows для msi u120

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

We are thankful for your never ending support.

Источник

How to List Files Ordered by Size in Linux

The first line displays the entire size of the directory you are listing files in. When adding the -l option the output will display file permissions in the first column, the hard links, the owner, the group, the size in bytes, month, day and time and finally the filename.

If you want to sort this output according to file size, from bigger to smaller you need to add the -S (Sort) option.

As you can see the output lists the files and directories sorted by size, but in bytes which is not very human friendly (1 Byte is 0.000001 MB in decimal and 0.00000095367432 MB in binary).

To print the output in a human friendly way you only need to add the -h (human friendly) option:

As you can see in the output above, now file sizes are shown in GB, MB, KB and Bytes.
Yet you are only seeing regular files without hidden files, if you want to include hidden files in the output you need to add the option -a (all) as shown below:

As you can see hidden files (starting with a dot) are printed too now.

Additional tips:

The following additional tips will help you to limit the output to a specific unit size different than bytes. The problem of this option is the output is never exact when the file is smaller or bigger than an exact number of that unit.

If you want to print in a specific size unit only instructing ls to display all files with the closest size in that unit only you can achieve it, for example, to print all files in MB you can add –block-size= options specifying MB with M as shown in the syntax and screenshot below:

As you can see now the size is in MB only, the bigger file is 115 MB, the second 69 MB, etc. Files with KB or Bytes size won’t be printed accurately, they will be shown as 1 MB which is the closest size can be printed if limited to MB.
The rest of the output remains exactly the same.

Using the same option (–block-size=) you can display the output in GB size instead of MB or bytes, the syntaxis is the same, replace the M for a G as in the example below:

Читайте также:  Блокировка windows нет рабочего стола

You can also print the size in KB units by replacing the M or G for a K:

All the examples above will list files and directories sorted by size in the unit you want, with the clarified problem mentioned above the output wont be accurate for files which don’t match a exact unit size. Additionally, these examples didn’t include hidden files (which start with a .). To do so, you will need to add the option -a (all) which will display hidden files too, therefore, to print files sorted by size by bytes run:

As you can see now hidden files, starting with a . (dot) are printed, such as .xsession-errors, .ICEauthority, etc.

If you want to print files and directories sorted by size in MB including hidden files run:

To print or display all files and directories sorted by size shown in GB including hidden files run:

Similarly to previous commands, to print files and directories ordered by size shown in KB including hidden files run:

Conclusion:

The command ls brings a lot of functionalities which help us to manage files and print information on them. Another example could be the use of ls to list files by date (with -lt options).

I hope you found this tutorial on How to list all files ordered by size in Linux useful. Keep following LinuxHint for more tips and updates on Linux and networking.

About the author

David Adams

David Adams is a System Admin and writer that is focused on open source technologies, security software, and computer systems.

Источник

How to Find Out Top Directories and Files (Disk Space) in Linux

As a Linux administrator, you must periodically check which files and folders are consuming more disk space. It is very necessary to find unnecessary junk and free up them from your hard disk.

This brief tutorial describes how to find the largest files and folders in the Linux file system using du (disk usage) and find command. If you want to learn more about these two commands, then head over to the following articles.

How to Find Biggest Files and Directories in Linux

Run the following command to find out top biggest directories under /home partition.

Find Largest Directories in Linux

The above command displays the biggest 5 directories of my /home partition.

Find Largest Directories in Linux

If you want to display the biggest directories in the current working directory, run:

Читайте также:  Центр поддержки windows 10 где находится

Find Biggest Directories Only

Let us break down the command and see what says each parameter.

  1. du command: Estimate file space usage.
  2. a : Displays all files and folders.
  3. sort command : Sort lines of text files.
  4. -n : Compare according to string numerical value.
  5. -r : Reverse the result of comparisons.
  6. head : Output the first part of files.
  7. -n : Print the first ‘n’ lines. (In our case, We displayed the first 5 lines).

Some of you would like to display the above result in human-readable format. i.e you might want to display the largest files in KB, MB, or GB.

Find Top Directories Sizes in Linux

The above command will show the top directories, which are eating up more disk space. If you feel that some directories are not important, you can simply delete a few sub-directories or delete the entire folder to free up some space.

To display the largest folders/files including the sub-directories, run:

Find Largest Folder and Subdirectories

Find out the meaning of each option using in above command:

  1. du command: Estimate file space usage.
  2. -h : Print sizes in human-readable format (e.g., 10MB).
  3. -S : Do not include the size of subdirectories.
  4. -s : Display only a total for each argument.
  5. sort command : sort lines of text files.
  6. -r : Reverse the result of comparisons.
  7. -h : Compare human readable numbers (e.g., 2K, 1G).
  8. head : Output the first part of files.

Find Out Top File Sizes Only

If you want to display the biggest file sizes only, then run the following command:

Find Top File Sizes in Linux

To find the largest files in a particular location, just include the path beside the find command:

Find Top File Size in Specific Location

The above command will display the largest file from /home/tecmint/Downloads directory.

That’s all for now. Finding the biggest files and folders is no big deal. Even a novice administrator can easily find them. If you find this tutorial useful, please share it on your social networks and support TecMint.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

We are thankful for your never ending support.

Источник

Оцените статью