How to find the list of 5 largest file in current directory?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to find the list of 5 largest file in current directory?
# 1  
Old 01-20-2009
How to find the list of 5 largest file in current directory?

Hello,
How to find the list of 5 largest(size wise) file in current directory?i tried using

Code:
    ls -l | sort -t " " -r +5 -6 -n | head -5

but this is not giving correct output as ls -l command gives 1 extra line of output that is how many total files are there!so by running the above command i get that also in the output also there are directories and even though its size is displaying 0 but that also is coming in output. Thanks in advance! Smilie
# 2  
Old 01-20-2009
Can check the switches in the ls man page to turn the total off, or use "grep -v total" to remove that line but you might have the problem that any line with a file or directory named "total" will be excluded too.
You can also pipe the ls into for example sed or awk to remove the 1st or last line, wherever the total is listed in your os/ls.
# 3  
Old 01-20-2009
Something like this should do the job:

Code:
ls -l|sort -n -k 5,5|tail -5|awk '{print $9}'

If you have files with spaces you can add more fields with the print command of awk:

Code:
ls -l|sort -n -k 5,5|tail -5|awk '{print $9,$10,$11}'

Regards
# 4  
Old 01-20-2009
to restrict to files in current dir only:

Code:
#  find * -prune -type f | xargs du -sk {}\; | sort -rn | sed 5q

should work
# 5  
Old 01-28-2009
This should do as its very simple

du -a "dir" |sort -n -r|head -n 5
Ashok_oct22
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

find the file names having specified pattern at specified position in the current directory

I would need a command for finding first 15000 of the file names whose 25th postion is 5 in the current directory alone. I do have this painful command find . -name '5*' | head -15000 | cut -c3- please refine this. Of course the above command also searches in the sub directories... (3 Replies)
Discussion started by: vk39221
3 Replies

2. Shell Programming and Scripting

To Find the largest file in the given directory.

Hi Experts, 1. In unix how to list the largest file in given directory. The answer will in single line statement. 2. I have Sun solaris live CD .I try to compile sample c program using "CC compiler".But its shows "cc command not found". Please help on this. Thanks in advance.... (4 Replies)
Discussion started by: kkl
4 Replies

3. Shell Programming and Scripting

Command to find largest file.

Hi All, Is there a direct Linux command to find the largest file by checking recursively in all the directories. (3 Replies)
Discussion started by: paragkalra
3 Replies

4. UNIX for Dummies Questions & Answers

Best way to find largest files in a directory

What is the best way to find the largest files in a directory? I used du -k|sort -rn |less. I got a results for this. But if I used the following command , I got another result...a different order in the same directory. Why is that? ls -la |awk '{print $5," ",$9}' sort -rn|less. I saw that... (6 Replies)
Discussion started by: Pouchie1
6 Replies

5. Shell Programming and Scripting

Find and display largest file on system

What is the correct command for finding and displaying the largest file on the system? I don't know how to specify "largest" with "find", and pipe that to something that will display the file contents. Or should I be using cat, more, less, ls, or something else? (4 Replies)
Discussion started by: raidkridley
4 Replies

6. HP-UX

find the largest file in whole system

find the largest file in whole system (7 Replies)
Discussion started by: megh
7 Replies

7. Shell Programming and Scripting

find largest file

Hi, 1)I have XX directory and have lot of files ,I want to find largest file in that directory 2)how calculate the size of file in MB. Thanks, Mohan (15 Replies)
Discussion started by: mohan705
15 Replies

8. Filesystems, Disks and Memory

find the 5o largest files in a directory

I'm trying to find the 50 largest file in a directory named /sasdb and its' subdirectories. I'm using the find command and a pipe to awk Not sure if I'm actually getting the largest files from this directory and its subdirectories. Here is the code I used... find /sasdb -ls | awk '{print... (8 Replies)
Discussion started by: igidttam
8 Replies

9. UNIX for Dummies Questions & Answers

list largest files in a directory & its subdirectories

I need to find the largest files in a directory & it's subdirectories. I'm not sure what options on ls -l will work to give me this. or is there another way to do this? Thanks, igidttam (6 Replies)
Discussion started by: igidttam
6 Replies

10. Programming

Finding largest file in current directory?

I was hoping to get some assistance with this C program I am working on. The goal is to find the largest file in the current directory and then display this filename along with the filesize. What I have so far will display all the files in the current directory. But, how do I deal with "grabbing"... (1 Reply)
Discussion started by: AusTex
1 Replies
Login or Register to Ask a Question