Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listing files by size 1

Status
Not open for further replies.

grega

Programmer
Feb 2, 2000
932
0
16
GB
Is there a "standard" command that will do this? It's something I've always wondered about :) I currently have a rudimentary script to do it ...

#!/bin/ksh
# list n largest files under current directory (recursive)
[ $# != 1 ] && {
echo &quot;Usage: findbig <number to list>&quot;
exit 1
}

find . -type f -exec ls -l {} \;|tr -s &quot; &quot;|sort -k 5n|tail -$1|awk 'BEGIN {printf(&quot;\nBytes\tFilename\n---------------------\n&quot;)} {printf(&quot;%s\t%s\n&quot;), $5, $9}'

and another variation to just do the current directory.

Was just wondering if anyone else has another way?

Greg.
 
What about &quot;find ... -size [xxx] ...&quot;.

-size says &quot;find a file with size at least [xxx] bytes in size.

Bill.
 
I believe

find ... -size 100 ...

finds files which are exactly 100 blocks in size.

find ... -size +100 ...

finds files which are greater than 100 blocks and

find ... -size -100 ...

finds files which are less than 100 blocks.
CaKiwi
 
Maybe this helps

ls -l |sort +4n
 
Grega,

I ran your script and have some questions if you could answer for me.

I keep getting the &quot; Usage: findbig <number to list>&quot; message so I was wondering why would I get that and what can I do to make the script run? Also what does 'tr -s &quot; &quot;' do?

Thanks

 
You need to give the script a number (which is used by the tail command to decide how many lines to display). For example, to display the 10 largest files, you would do findbig 10.

tr -s &quot; &quot; removes all the repeating spaces from the line, so &quot;word1 word2&quot; would become &quot;word1 word2&quot;

I still think I prefer unixadmin's solution above :)

If you want to do it recursively you could do ls -lR | sort +4n

Greg.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top