The ls command is used to list directory contents under Linux and Unix like operating systems. If no options or operands are given, the contents of the current directory are displayed on the screen. By default entries are sorted alphabetically if none of the -cftuvSUX nor --sort option passed to the ls command.
The default output (sort by alphabetically)
Type the following command:
$ ls
$ ls *.py
$ ls *.avi
Sample outputs:
Force sort by size option
You need to pass the -s or --sort=size option as follows:
$ ls -s
$ ls --sort=size
$ ls --sort=size *.avi
$ ls -s *.avi
Sample outputs:
You will see largest file first before sorting the operands in lexicographical order. The following command will sort file size in reverse order:
$ ls -l -S | sort -k 5 -nOR try (see comments below, thanks!):
$ ls -lSrSample outputs:
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop















{ 6 comments… read them below or add one }
Instead of
$ ls -l -S | sort -k 5 -n
this works also
$ ls -l -S -r
-r = reverse order
Or just do
ll -Sr
:)
ll is alias to ‘ls -l’. Although it it configured on many linux distros, it does not have to be and therefore not guaranteed to work.
Even better is:
$ ls -lrS
Raphael, Roy, and dru,
Thanks for the heads up. The faq has been updated.
what I do is this:
du -xak . | sort -n | tail -100
it finds me the biggest 100 files or directories on the filesystem I’m in