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,
- Rename a directory using Linux/Unix command
- ls command to list only directories
- How to Restart or Reload Nginx Server Service on Linux
- 3 ways to clear screen on Linux Terminal
- ls command: sort files by name alphabetically A-Z or Z-A [Linux/Unix/macOS/Bash]
- Copy entire directory using Terminal Command [Linux, Mac, Bash]
- Fix: sudo: unable to open Read-only file system
- Create Hidden File or Directory using Shell Command
- Command to know the installed Debian version?
- The Date Command and its usage [Linux - Unix - macOS]
- Fix - bash: man: command not found
- How to tar.gz a directory or folder Command
- How to Display content of a file in Terminal Screen?
- How to change bash terminal prompt string and color
- Sort ls command by last modified date and time
- Execute .bin and .run file Ubuntu Linux
- zsh hello world example
- How to check uptime of Linux/Unix/macOS system/server using console command?
- [Fix] Linux - bash: useradd: command not found
- Command to check Last Login or Reboot History of Users and TTYs
- How to install and Configure sar sysstat tools in Ubuntu Linux
- How to use SCP Command to Copy Directory
- Linux Remove or Delete Files and Directories using Terminal Commands
- How to connect to SSH port other than default 22
- Install OpenSSL on Linux/Ubuntu
More Posts:
- How to remove Extra Spaces in Notepad++ - NotepadPlusPlus
- Two Ways to Extract rar (*.rar) files on Mac - MacOS
- Java Multi-line String Example - Java
- Java 8 Leap year check using Year class from java.time api - Java
- Microsoft Lists and SharePoint Online edit grid view - use undo and redo changes - SharePoint
- How to get SharePoint List Item URL using PowerShell - SharePoint
- Docker Commit Command with Examples - Docker
- How to get Java Thread name Example [Program] - Java