Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 05-14-2005, 03:35 PM   #1
Senior Member
Registered: Sep 2004
Location: Sweden
Distribution: Ubuntu, Debian
Posts: 1,109

Rep: Reputation: 49
sort files after size

I want to find the biggest files on my root partition (exclude /boot and /home). How may I do that? Get some sort of list that is ordered by size.
Old 05-14-2005, 04:10 PM   #2
LQ Guru
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 250Reputation: 250Reputation: 250
du -h /boot | sort -n

something like that should do the trick.. man sort for more options, details.. etc.
Old 05-14-2005, 04:44 PM   #3
Registered: Jun 2004
Location: In Adamantine Chains and penal Fire
Distribution: Debian Sarge & Ubuntu Breezy
Posts: 107

Rep: Reputation: 16
Dammit! Someone always beats me to the punchline! Anyway, I have another good solution:
du --exclude boot --exclude home -ahB K / 2>/dev/null\
| perl -e 'my @a; while(<>) { chomp; unless (-d (substr($_,\ 
index($_,"/")))) { push(@a,$_); }}@b = sort {$b <=> $a}\
@a; foreach (@b) { print"$_\n";}'

Of course, you can remove the '2>/dev/null' if you're root, and change the "size granularity" by changing 'K' in 'du -ahB K' to things like "M" for megabytes, "G" for gigabytes, etc.

Of course, my script removes directory sizes (which du outputs as default), and will sort top to bottom the largest files on the system. Also, as long as you use absolute paths, this script will recursively list largest files in any directory; just change "/" after '-ahB K' to '/example/dir' and remove the '--exclude' entries! Thanks perl!

Last edited by six6; 05-14-2005 at 04:49 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script to sort files by extension otheralex Programming 7 08-19-2005 02:40 AM
Command line to sort files satimis Programming 6 06-28-2005 02:50 AM
How to sort files in a directory by date in KDE? Ace_Azzameen Linux - Software 7 05-24-2004 02:49 PM
How can it ell Grip where put my ripped files and sort the in the correct order MvD Linux - Software 2 10-16-2003 03:10 AM
increase point size size when printing PDF files newlin Red Hat 0 09-27-2003 07:13 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:25 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration