LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 10-09-2014, 11:55 PM   #1
byran cheung
Member
 
Registered: Sep 2013
Posts: 321

Rep: Reputation: Disabled
sort by size from largest to smallest


I just read the link and found that the command du /home/* | sort -n -r can sort the file from size ( from largest to smallest ) , but I can not do it , the result is still not ordered by size , would confirm is there any other way can sort by size ? thanks


http://serverfault.com/questions/624...output-by-size
 
Old 10-10-2014, 12:12 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 14,833

Rep: Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820
Quote:
Originally Posted by byran cheung View Post
... but I can not do it , the result is still not ordered by size
It probably is, actually. Lots of output probably scrolling off the screen - try this to see the biggest 20
Code:
du /home/* | sort -n -r | head -n 20
 
Old 10-10-2014, 12:53 AM   #3
byran cheung
Member
 
Registered: Sep 2013
Posts: 321

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by syg00 View Post
It probably is, actually. Lots of output probably scrolling off the screen - try this to see the biggest 20
Code:
du /home/* | sort -n -r | head -n 20
thanks reply ,

I use your method but the result is as below , it seems still not work ,

1000M .......
988M .......
974M .......
968M .......
964M .......
839M .......
816M .......
797M .......
643M .......
617M .......
518M .......
340K .......
502M .......
446M .......
304K .......
272M .......
 
Old 10-10-2014, 01:03 AM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 14,833

Rep: Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820
Your distro seems to have an alias for "du" - try this
Code:
du /home/* | sort -h -r | head -n 20
 
Old 10-10-2014, 01:06 AM   #5
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
Hi,

looks like you may have du aliased to 'du -h'. What is the output of
Code:
which du
Or try
Code:
\du /home/* | sort -n -r | head -n 20
Anyway even if using 'du -h' as long as you are using sort from coreutils and it's not ancient you can use the -h option.
Code:
du -sckxh /home/* | sort -hr | head -n 20
Check the man page of each command to understand the options.
Evo2.
 
Old 10-10-2014, 02:25 AM   #6
byran cheung
Member
 
Registered: Sep 2013
Posts: 321

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by syg00 View Post
Your distro seems to have an alias for "du" - try this
Code:
du /home/* | sort -h -r | head -n 20
thank reply ,

when use your command , it pops the below
===========================================
sort: invalid option -- h
Try `sort --help' for more information.
===========================================
I also tried du /home/* | sort -r | head -n 20 but still not work.

Last edited by byran cheung; 10-10-2014 at 02:48 AM.
 
Old 10-10-2014, 03:02 AM   #7
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
Hi,
Quote:
Originally Posted by byran cheung View Post
when use your command , it pops the below
===========================================
sort: invalid option -- h
Try `sort --help' for more information.
===========================================
Try the 2nd piece of code in my post.

Evo2.
 
Old 10-10-2014, 03:18 AM   #8
byran cheung
Member
 
Registered: Sep 2013
Posts: 321

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by evo2 View Post
Hi,

Try the 2nd piece of code in my post.

Evo2.

sh-3.2# du -sckxh /home/* | sort -hr | head -n 20
sort: invalid option -- h
Try `sort --help' for more information.
 
Old 10-10-2014, 03:28 AM   #9
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,104

Rep: Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267
if you cannot use sort -h you must not use du -h but du -sk /home/* | sort -nr
 
Old 10-10-2014, 03:44 AM   #10
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
Hi,

that is not the 2nd piece of code I posted. It is simply the same command that you were first trying to run but with a leading backslash to escape the alias. Here it is again.
Code:
\du /home/* | sort -n -r | head -n 20
Evo2.
 
  


Reply


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
[SOLVED] Store the size of largest file from a file/directory listing into variable SIZE lainey Linux - Newbie 3 11-15-2011 01:29 PM
smallest and largest of three numbers emation06 Programming 10 10-22-2006 12:30 AM
Largest Recommended Partition Size soopafresh Linux - Newbie 3 08-08-2004 05:02 AM
largest hard drive size teuben Linux - Hardware 2 01-27-2004 09:11 AM
largest recommended partion size gwroy20 Linux - General 2 09-07-2003 09:16 PM


All times are GMT -5. The time now is 10:15 PM.

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