≡ Menu

How to find large files

In Windows, if one wants to find which files are consuming most of the space on the disk, it can be found easily using explorer. Just sort list of the files based on the size attribute. But what if we need to find the large sized files from command line? How can we do this?

We can find this using windows commands, without needing any third party tools.  We can do this using forfiles command.

Find files with size of 1 MB or more.

forfiles /S /M * /C "cmd /c if @fsize GEQ 1048576 echo @path"

Example:

c:\users\mike>forfiles /S /M * /C "cmd /c if @fsize GEQ 1048576 echo @path"

"c:\Users\mike\AppData\Local\Microsoft\MSOIdentityCRL\Tracing\msoidLiteTrace{9317BCB6-314B-442F-A5DA-9BC2BEBC271D}.txt"
"c:\Users\mike\Documents\work\May-2014.txt"
"c:\Users\mike\Documents\work\tmp\feed.txt"
"c:\Users\mike\Documents\work\tmp\syslog.txt"

This command prints the complete file path. If you need to print just the file name, you can use @file in place of @path.

Command to find files with size of more than 100MB

forfiles /S /M * /C "cmd /c if @fsize GEQ 104857600 echo @path"

Find files with size 1 GB or more.

forfiles /S /M * /C "cmd /c if @fsize GEQ 1073741824 echo @path"

As shown above, this command allows us to find files having size more than a given value. It’s not useful if someone wants to find the largest 10 files in a folder. I could not find a way to do this using windows native commands. If you know of any way to do this, please let others know by adding comment below.

19 comments… add one
  • Robert

    When running it from the root of a server I get “Error: The filename or extension is too long.” message.

    I have not yet, but I will try running is several folder in from a data share.
    I also created a batch file to run it and where I placed the bat was not in the path, so I had to precede the command with the path. I also changed from *.txt to *.* as I want to see all files over a gig in size.
    Thanks!

    • admin

      Thanks. I updated the commands to consider all file types.

  • Teja

    What should be the command to find top ‘x’ files. For example, I need to find top 10 big files on my system.

  • Kala Sha Jahan

    works, but only searches the current user profile. can it search every user profile?

    • Srini

      If you run the command from C:\, you can search across all user profiles.

  • albina elvira

    The path you entered, is too long. Enter a shorter path
    File Name could not be found. Check the spelling of the filename,
    and verify that the file location is correct.

  • Arcindo

    O meu resultado foi este http://i.imgur.com/wD8Oycv.png

    • J C

      That’s powershell… not Command Prompt.

  • NotABot

    For those wanting top 10 files, redirect output to a text file such as
    forfiles /S /M * /C “cmd /c if @fsize GEQ 1073741824 echo @path > bigfiles.txt”

    You can then open in excel and sort or use text editor to weed out the files you don’t want

  • karl

    Better to run command prompt as an administrator, elevated command prompt.

  • Lance

    What if I want to get all the folders with a total size greater than 100Mb ?

  • Fagner

    Large sizes don’t works well. If you try files beq 16106127360 (15GB), for example, the command don’t works fine.

  • SteveL

    Hello,
    On my Win10 1809 April 3, 2019, the code by OP fails because IF is testing strings no integers.
    Place % on each side of strings to force an integer compare.
    e.g.
    forfiles /S /M * /C “cmd /c if %@fsize% GEQ %1048576% echo @path”

    I had to use the following to find files larger than 5GB.
    forfiles /S /M *.mp4 /C “cmd /c if %@fsize% geq %5368709120% echo @file-@fsize”

    The following shows my results without the integer conversions. Excamaitions added to mark the incorrect finds.
    G:> forfiles /S /M *.mp4 /C “cmd /c if @fsize GEQ 5177382727 echo @file – @fsize”

    “16.52.34.01-trim.mp4” – 6277215671
    “16.52.34.01-m.mp4” – 3071602259 !!
    “15.47.35.01.mp4” – 5568346966
    “16.03.45.02.mp4” – 5177382727
    “17.03.06.03.mp4” – 10017167364
    “17.38.29.05.mp4” – 5095886996
    “18.24.25.07.mp4” – 6714514328
    “18.49.21.08.mp4” – 2207037683 !!
    “19.28.46.01.mp4” – 3932554504 !!

  • When I run forfiles /S /M * /C “cmd /c if @fsize GEQ 1073741824 echo @path”, command gives me the following message ERROR: The filename or extension is too long.

  • Kenneth Frey

    I had success with the original command. However, it only gives me the path and file name. I’d like to see the size of each file. Is there a switch for that?

    • Hernando

      use @fsize after the echo to see the size in bytes

  • JOHN

    thanks.

  • Robert

    This works, but there is at least one issue: performance!

    On a bare bones win 10 system with Office Pro installed, it can take as much as 12 hours to find all of the large files (!)

    Here’s the TL;DR part…

    The suggested solution (forfiles /S /M * /C “cmd /C if @fsize GEQ 1000000 echo @path”) will spawn a new instance of the Windows command processor (cmd.exe) is spawned for *every* file if finds (!)

    Spawning a new process is a relatively costly procedure for *any* operating system. Not surprisingly it is particularly laborious in Windows. In fact, I’ve measured the spawn rate of ~7 spawns per second on my 64 bit Windows 10 Enterprise system (i7-10850H 2.7GHz, 32G RAM and a 1TB SSD drive)

    That rate is for doing nothing. It simply spawned cmd.exe and exited right away in a loop, 1k times. Essentially this 7 spawns/sec is the maximum spawn rate Windows 10 can perform on my particular machine. YMMV, although my system is a fairly decent system per 2022 standards.

    Note that there’s no parallelism here. The cmd.exe are spawned serially by the same parent process. That is exactly how the forfiles command is going to work (AFAIK, and, according to my measurements, it *is* how forfiles works).

    Now, let’s assume the best case scenario and that the command to be run inside the newly spawned cmd.exe (i.e., “if @fsize GEQ 1000000 echo @path”) runs at least an order of magnitude quicker than spawning cmd.exe (in my tests, this seems to be the case). That means the additional time doing the filesize comparison is negligible (for the purposes of our discussion).

    I ran a batch file that spawned 1024 cmd.exes that did nothing. Then I ran the forfiles command in a directory containing 1024 files. They *both* took about 2.5 minutes.

    This means our forfiles command, on my system, can process a maximum of just under 7 files per second.

    So, let’s say we’ve got a system with Windows 10 Enterprise and Microsoft Office Pro. AFAIK such a system is going to have approximately 300,000 files (mine has 583k files, but I have some additional software installed). Let’s say there is little to no user data on the drive. If you want to find the big files on such a system using forfiles, it is going to take …

    300000 / 7 = 42,857 seconds = 11 hours, 54 minutes.

    Yikes!

    So, the forfiles solution is perfectly valid, but I did want to point out to future readers the fact that this solution could take a very long time if you’re searching most or all of your C: drive.

  • Bruce Pleat

    To set a range (in my case, 2G-3G – decimal since I wasn’t needing to be precise) just add the second “if”:
    forfiles /S /M * /C “cmd /c if @fsize GEQ 2000000000 if @fsize LEQ 3000000000 echo @path”

Leave a Comment