Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I find the 10 largest files in a directory structure

Tags:

powershell

How do I find the 10 largest files in a directory structure?

like image 331
Ralph Shillington Avatar asked Apr 28 '09 13:04

Ralph Shillington


2 Answers

Try this script

Get-ChildItem -re -in * |   ?{ -not $_.PSIsContainer } |   sort Length -descending |   select -first 10 

Breakdown:

The filter block "?{ -not $_.PSIsContainer }" is meant to filter out directories. The sort command will sort all of the remaining entries by size in descending order. The select clause will only allow the first 10 through so it will be the largest 10.

like image 142
JaredPar Avatar answered Oct 13 '22 06:10

JaredPar


This can be simplified a bit because Directories have no length:

gci . -r | sort Length -desc | select fullname -f 10 
like image 34
Keith Hill Avatar answered Oct 13 '22 07:10

Keith Hill