LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Help finding three largest files on system (https://www.linuxquestions.org/questions/linux-newbie-8/help-finding-three-largest-files-on-system-812451/)

F4U57 06-06-2010 08:07 AM

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.:o

Thanks.

grail 06-06-2010 08:14 AM

Have you looked at the 'S' option for ls

colucix 06-06-2010 08:19 AM

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.

F4U57 06-07-2010 09:37 PM

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.

colucix 06-08-2010 03:04 AM

Quote:

Originally Posted by F4U57 (Post 3996066)
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).


All times are GMT -5. The time now is 11:51 AM.