How to List All the Files Sorted by Size in Linux (RHEL / CentOS 7/8)

In this article, I will show you how to List All the Files Sorted by Size in Linux (RHEL/CentOS 7/8). Many times you might have faced a situation where you need to List all the files sorted by size in Linux Based Systems. If you are a Linux Professional then I am sure you must be aware of ls command in Linux to List all the files and directories. Using different options of ls command you can List all your files sorted by size in Linux. You can check more on that by going through below shown examples.

How to List All the Files Sorted by Size in Linux (RHEL / CentOS 7/8) 1

List All the Files Sorted by Size in Linux

Also Read: How to Install Screen Command in Linux (RHEL / CentOS 7/8) Using 4 Easy Steps

If you want to List all the Files ordered by size in Linux then you need to use -S option with ls command as shown below. By default, if you use -S option with ls command then file will be listed in descending order. It means the file with the largest size will show first and then so on.

The other flag that you see here used with ls command is -l which is used for long listing format and -a which is used for listing all the files including the one starting with dot(.)

[root@localhost ~]# ls -laS
total 494324
-rw-------.  1  root root  288832000 May 11 21:16  testswap
-rw-r--r--   1  root root  146669568 Jun 13 06:25  CentOS.ISO
-rw-r--r--   1  root root  32986501  Jun 10 10:04  awscliv2.zip
-rw-r--r--.  1  root root  30629808  May 24 01:22  moduli-2048.candidates
-rw-r--r--.  1  root root  5453837   Jun 2  17:19  master.zip
-rw-r--r--   1  root root  1177864   Jun 6  16:46  file.txt
-rw-r--r--.  1  root root  215305    Apr 28 01:30  file.zip
-rw-------.  1  root root  29622     Jul 24 04:53  .bash_history
drwxr-xr-x.  11 root root  12288     May 11 05:00  radius
-rw-r--r--.  1  root root  10240     Apr 27 23:17  file.tar
-rwxr-xr-x   1  502  games 4628      Jul 7  09:16  hello.sh
dr-xr-x---.  27 root root  4096      Jul 20 00:23  .
drwxr-xr-x   18 root root  4096      Jul 20 03:17  eus
-rw-r--r--.  1  root root  3517      Apr 26 01:45  sysaix.pfx
-rw-r--r--.  1  root root  2690      May 11 02:09  Network.java
-rw-r--r--.  1  root root  2409      May 11 06:37  Network.class
-rw-r--r--   1  502  games 2291      Jul 7  09:34  Source.txt
-rw-r--r--.  1  root root  1743      Apr 26 01:31  server.key
-rw-r--r--.  1  root root  1743      Apr 23 19:16  testserver.key.local
-rw-r--r--.  1  root root  1675      Apr 26 01:34  newserver.key

Similarly, If you want to List all the Files in ascending order then you need to use -r option along with -S option with ls command as shown below. Using -r option will List the file with smallest size first and then so on.

[root@localhost ~]# ls -lrS
total 494236
-rw-r--r--  1 root root 0  Jun 21 15:55 Running
-rw-r--r--. 1 root root 0  Apr 27 22:41 root@192.168.0.105
-rw-r--r--  1 root root 0  Jun 21 15:55 Processing
prw-r--r--. 1 root root 0  Apr 29 03:55 pipe
-rw-r--r--  1 root root 0  Jun 21 15:55 Package
-rw-r--r--  1 root root 0  Jun 21 15:55 Finished
-rw-r--r--. 1 root root 0  Apr 27 22:41 admin@192.168.0.105
drwxr-xr-x  2 root root 6  Jun 9  03:08 192.168.0.106
drwxr-xr-x  2 root root 6  Jun 9  03:08 192.168.0.105
drwxr-xr-x  2 root root 6  Jun 9  03:08 192.168.0.103
lrwxrwxrwx. 1 root root 9  May 21 01:07 file -> file1.txt
-rw-r--r--. 1 root root 10 Jul 11 04:37 output.txt
-rw-r--r--  1 root root 13 Jun 23 16:40 testfile.txt
drwxr-xr-x  2 root root 16 Jun 17 01:25 Logs
drwxr-xr-x  2 root root 17 Jun 9  03:08 192.168.0.107
lrwxrwxrwx  1 root root 20 Jun 20 20:02 sshd_config -> /etc/ssh/sshd_config
-rw-r--r--  1 root root 29 Jun 18 03:23 hello.txt
drwxr-xr-x  2 root root 35 Jun 28 14:02 example
-rw-r--r--  1 root root 39 Jun 18 03:22 hosts
drwxr-xr-x. 3 root root 40 Jun 25 09:21 testdir
-rw-r--r--. 1 root root 46 Apr 28 00:56 file2.txt
drwxr-xr-x  4 root root 48 Jun 9  03:12 example.text
drwxr-xr-x  3 root root 60 Jun 17 01:24 output
drwxr-xr-x  3 root root 65 Jun 25 09:21 error

If you want to check all the other options that can be used be ls command then you need to use ls --help command as shown below.

[root@localhost ~]# ls --help
Usage: ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.

Mandatory arguments to long options are mandatory for short options too.
-a, --all do not ignore entries starting with .
-A, --almost-all do not list implied . and ..
--author with -l, print the author of each file sorted by size
-b, --escape print C-style escapes for nongraphic characters
--block-size=SIZE scale sorted by SIZE before printing them; e.g.,
'--block-size=M' prints sizes in units of
1,048,576 bytes; see SIZE format below

 

 

 

Popular Recommendations:-

Advertisements

How to Disable IPV6 on Linux (CentOS / RHEL 7/8) Using 4 Best Steps

How to Set MariaDB root Password in RHEL/CentOS 7/8 Using Simple mysql_secure_installation

Introduction to SQL Injection Attacks in MySQL (v5.5)

How to Create Table in MySQL 5.5 with Easy Steps

How to Limit CPU Limit of a Process Using CPULimit in Linux (RHEL/CentOS 7/8)

How to Install Rust Programming Language in Linux Using 6 Best Steps

How to Install LEMP Stack on CentOS 8

Openssl Tutorial: Generate and Install Certificate on Apache Server in 8 Easy Steps

How to Enable or Disable SELinux Temporarily or Permanently on RedHat/CentOS 7/8

Top 12 Nmap Commands to Scan Remote Host with Best Practices

Advertisements

Leave a Reply