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,
- Command to know the Available Memory on Linux System
- How to install curl on Alpine Linux
- How to backup a file in Linux/Unix
- Install Java Runtime Environment (Oracle or open JRE) on Ubuntu
- What is the Default Admin user and Password for Jenkins
- How to tar.gz a directory or folder Command
- Copy entire directory using Terminal Command [Linux, Mac, Bash]
- Fix: bash: ipconfig: command not found on Linux
- Command to check Last Login or Reboot History of Users and TTYs
- Linux: Create a New User and Password and Login Example
- ls command to list only directories
- bash: cls: command not found
- How to exit from nano command
- Installing and using unzip Command to unzip a zip file using Terminal
- What does apt-get update command does?
- ls command: sort files by name alphabetically A-Z or Z-A [Linux/Unix/macOS/Bash]
- How to remove or uninstall Java from Ubuntu using apt-get
- scp: ssh: connect to host xxxx port 22: Connection refused Error
- Sort ls command by last modified date and time
- Create Nested Directories using mkdir Command
- How to Exit a File in Terminal (Bash/Zsh)
- Command to know the installed Debian version?
- How to connect to SSH port other than default 22
- How to save a file in Nano Editor and Exit
- Install OpenSSL on Linux/Ubuntu
More Posts:
- Division between two numbers - C-Program
- How to install Microsoft Teams on Mac using Terminal (Silently) - Teams
- How to lock Notepad++ tabs? - NotepadPlusPlus
- Add or remove users from sudo group - Ubuntu - Ubuntu
- Shortcut: How to delete a complete line in Nano Editor - Linux
- Java JDBC Connection with Database using SSL (https) URL - Java
- Json Serialization and Deserialization using Java Jackson - Java
- [Java Threads] Should we extend Thread Class or implement Runnable interface - Java