Q. How do I list or find the smallest directories or files in the current directory under Linux or UNIX like operating system?
A. There is no direct command exists for this task. However by using shell pipes and combination of other commands one can produced the desired result.
Task: Display list of smallest files
You need to use ls command and pass the option -l (long format) -S (sort) -r (in reverse order), enter:
$ ls -lSr
$ ls -lSr
$ ls -lSr | head
$ ls -lSr | head -5
Output:
-rw-r--r-- 1 root root 0 May 29 07:08 Muttrc.local -rw-r--r-- 1 root root 0 Jan 12 2000 motd -rw-r--r-- 1 root root 0 Jan 12 2000 exports -rw-r--r-- 1 root root 0 Nov 28 2006 environment -rw-rw-r-- 1 root disk 0 Aug 7 2006 dumpdates -rw-r--r-- 1 root root 0 Jul 10 08:50 cron.deny -rw------- 1 root root 1 Aug 23 2006 at.deny lrwxrwxrwx 1 root root 7 Jul 10 08:50 rc -> rc.d/rc lrwxrwxrwx 1 root root 10 Jul 10 08:50 rc6.d -> rc.d/rc6.d lrwxrwxrwx 1 root root 10 Jul 10 08:50 rc5.d -> rc.d/rc5.d lrwxrwxrwx 1 root root 10 Jul 10 08:50 rc4.d -> rc.d/rc4.d lrwxrwxrwx 1 root root 10 Jul 10 08:50 rc3.d -> rc.d/rc3.d lrwxrwxrwx 1 root root 10 Jul 10 08:50 rc2.d -> rc.d/rc2.d
Task: Display list of smallest directories
You need to use du command to display sorted (-S option) output. Use pipe to send du command output to sort command for sorting purpouse:
$ du -S . | sort -n
$ du -S . | sort -n | head -10
Output:
du -S . | sort -n | head -10 4 ./lighttpd/ssl 4 ./monit.d 8 ./acpi 8 ./acpi/actions 8 ./alchemist 8 ./alchemist/namespace 8 ./alternatives 8 ./desktop-profiles 8 ./dev.d 8 ./dev.d/default
Read the man page of ls, sort and du for more options:
man ls
man du
man sort
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











{ 0 comments… add one now }