LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 06-06-2010, 09:07 AM   #1
F4U57
LQ Newbie
 
Registered: Jun 2010
Posts: 5

Rep: Reputation: 0
Help finding three largest files on system


Hi, I'm having problems with a bash script command to find the three largest files on my system. This is probably fairly simple, but I've been at this for hours without luck.

I've done some research and it seems as though

# ls -lh | sort +4n | tail -3

is what should relay the information I need, but when typed, it comes up with the error +4n: No such file or directory. Is there another way around this?

I've also tried

# du -a / | sort -n -r | head -n 3

but this is giving me the largest directories under root. Having issues.

Thanks.
 
Old 06-06-2010, 09:14 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,252

Rep: Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685
Have you looked at the 'S' option for ls
 
Old 06-06-2010, 09:19 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Maybe you did mean
Code:
sort -k5n
anyway you need a tool that can descend recursively into the directory tree. Have a look at find.

Last edited by colucix; 06-06-2010 at 10:19 AM. Reason: Maybe it's too late, but I've just realized this was a homework question...
 
Old 06-07-2010, 10:37 PM   #4
F4U57
LQ Newbie
 
Registered: Jun 2010
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks colucix, I think the find is better suited to what I am searching for.

Code:
find . -size +"." -a -size -"."
Will find files within listed sizes but is there a way i can get them to list the the three largest (taken from Wikipedia). Unfortunately I don't have a linux OS to try this on at the moment, but was thinking

Code:
find . | sort -n -r | head -n 3
If someone could try this and see if it works that would be great.
 
Old 06-08-2010, 04:04 AM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Quote:
Originally Posted by F4U57 View Post
Unfortunately I don't have a linux OS to try this on at the moment, but was thinking
Well... you definitively should have it. The learning process is far more quicker and effective if you can "try and find out"!

Anyway, your command does not work as you expect. First run the find command alone and see what is the output. Then think about the first command after the pipe (sort -n)... is there something in the output of find that can be sorted numerically? Does the find command print out the file size if you don't force it explicitly?

An hint: in the man page of find (or in the GNU find online manual) look at -size (to restrict the search to files greater than...) and -printf (to customize the output).
 
  


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
Is the VA's VistA health information system the largest open source Linux app? Jon_Roland Linux - General 1 01-27-2009 09:49 PM
Finding files and then finding content within those files... Maeltor Linux - Software 5 03-13-2007 01:06 PM
LXer: World's Largest Linux System Image Achieved on SGI Altix 4700 Blade Servers LXer Syndicated Linux News 0 06-27-2006 01:03 PM
Find 100 largest files in folder tree tyreth Linux - General 2 02-07-2006 09:18 AM


All times are GMT -5. The time now is 09:13 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