You need to make use of -S option in order to sort the list of files using ls command based on file sizes. -S option will sort all the result in the ls command based on the size of the files/dir in greatest to lowest. If you wish to display the list in reverse order smallest to the bigger file size you can use reverse you can add -r. example ls -lSr
Syntax: ls -lS
Example:Without sorting by file size
$ ls -l
total 32
drwxr-xr-x 1 root root 87188 Aug 18 09:54 bin
drwxr-xr-x 2 root root 4096 Apr 24 2018 boot
drwxr-xr-x 1 root root 4096 Aug 12 20:40 abc
drwxr-xr-x 5 root root 360 Aug 22 10:57 dev
drwxr-xr-x 1 root root 4896 Aug 18 10:47 etc
drwxr-xr-x 1 root root 232 Aug 18 11:17 ext
drwxr-xr-x 1 root root 4096 Aug 12 20:40 home
drwxr-xr-x 1 root root 17526 Aug 18 09:53 lib
drwxr-xr-x 1 root root 2422 May 27 12:25 lib32
drwxr-xr-x 1 root root 40 May 25 12:51 lib64
drwxr-xr-x 1 root root 2544 May 27 12:25 libx32
drwxr-xr-x 2 root root 4096 Jul 13 14:48 media
drwxr-xr-x 2 root root 4096 Jul 13 14:48 mnt
drwxr-xr-x 1 root root 64 Jul 30 12:41 opt
dr-xr-xr-x 1045 root root 0 Aug 22 10:57 proc
drwx------ 2 root root 4096 Jul 13 14:49 root
drwxr-xr-x 1 root root 4096 Aug 12 20:40 run
drwxr-xr-x 1 root root 8994 Aug 18 09:53 sbin
drwxr-xr-x 4 root root 4096 Aug 22 10:57 secrets
drwxr-xr-x 1 root root 0 Apr 23 11:06 srv
dr-xr-xr-x 13 root root 0 Aug 22 10:57 sys
drwxrwxrwt 5 root root 100 Aug 22 11:01 tmp
drwxr-xr-x 1 root root 122 May 28 17:35 usr
drwxr-xr-x 1 root root 108 May 27 12:21 var
With sorting for file size:
$ ls -lS
total 32
drwxr-xr-x 1 root root 87188 Aug 18 09:54 bin
drwxr-xr-x 1 root root 17526 Aug 18 09:53 lib
drwxr-xr-x 1 root root 8994 Aug 18 09:53 sbin
drwxr-xr-x 1 root root 4896 Aug 18 10:47 etc
drwxr-xr-x 2 root root 4096 Apr 24 2018 boot
drwxr-xr-x 1 root root 4096 Aug 12 20:40 abc
drwxr-xr-x 1 root root 4096 Aug 12 20:40 home
drwxr-xr-x 2 root root 4096 Jul 13 14:48 media
drwxr-xr-x 2 root root 4096 Jul 13 14:48 mnt
drwx------ 2 root root 4096 Jul 13 14:49 root
drwxr-xr-x 1 root root 4096 Aug 12 20:40 run
drwxr-xr-x 4 root root 4096 Aug 22 10:57 secrets
drwxr-xr-x 1 root root 2544 May 27 12:25 libx32
drwxr-xr-x 1 root root 2422 May 27 12:25 lib32
drwxr-xr-x 5 root root 360 Aug 22 10:57 dev
drwxr-xr-x 1 root root 232 Aug 18 11:17 ext
drwxr-xr-x 1 root root 122 May 28 17:35 usr
drwxr-xr-x 1 root root 108 May 27 12:21 var
drwxrwxrwt 5 root root 100 Aug 22 10:57 tmp
drwxr-xr-x 1 root root 64 Jul 30 12:41 opt
drwxr-xr-x 1 root root 40 May 25 12:51 lib64
dr-xr-xr-x 1050 root root 0 Aug 22 10:57 proc
drwxr-xr-x 1 root root 0 Apr 23 11:06 srv
dr-xr-xr-x 13 root root 0 Aug 22 10:57 sys
✔️ This command works on all terminals: [Linix/UNIX/macOS/bash]
Comments:
- Perfect.. this is what I was looking for! Thanks
anonymous 05 Sep 2020 18:09:01 GMT
- Further comments disabled!
More Posts related to Linux,
- [Fix] Linux - bash: useradd: command not found
- Calculate days between dates using dateutils ddiff command
- pwd Command - Print Working Directory
- Rename a directory using Linux/Unix command
- How to go to the End of File in Nano Editor
- How to tar.gz a directory or folder Command
- How to remove/delete a directory in Linux/macOs
- How to Display content of a file in Terminal Screen?
- ls command sort by file size [Linix/UNIX/macOS/bash]
- How to Copy Entire Directory to another Directory in Linux
- 3 ways to clear screen on Linux Terminal
- Command to check Last Login or Reboot History of Users and TTYs
- How to check uptime of Linux/Unix/macOS system/server using console command?
- How to backup a file in Linux/Unix
- Command to know the installed Debian version?
- Check SSH/OpenSSH version Command
- 3 Commands to stop Nginx Server
- Linux: Create a New User and Password and Login Example
- How to install npm on Ubuntu
- How to List All Users in Linux
- How to Get the List of Shells on Linux
- Fix - ssh-copy-id no identities found error
- Installing and using unzip Command to unzip a zip file using Terminal
- scp: ssh: connect to host xxxx port 22: Connection refused Error
- zsh hello world example
More Posts:
- How to integrate Salesforce CRM Sales and Service with Microsoft Teams - Teams
- Deploy SharePoint wsp solution package using PowerShell - SharePoint
- How to install maven in macOS using Terminal Command - MacOS
- How to destroy PHP session() - PHP
- Install Oh My Zsh on Ubuntu Docker complete steps - Ubuntu
- How to Skip or Ignore JUnit test cases in Java - Java
- macOS Ventura 13: The default interactive shell is now zsh - zsh
- Turn Off Auto-Brightness on iPhone running iOS 16 - iOS