• How To?
  • Tips ‘n Tricks
  • WordPress
  • Snippets
  • Software
    • Browsers
    • Downloads
  • Web
  • Tools
    • Character Counter
    • chmod Calculator
    • Entities Encoder
    • Live HTML Editor
    • My IP
  • Contact
Twitter Facebook Google+ RSS
You are here: SumTips » Tips 'n Tricks » Find Files Larger than a Specific Size with PowerShell & CMD

Find Files Larger than a Specific Size with PowerShell & CMD

Posted on January 3, 2013 by Renji | Short URL: http://sumtips.com/?p=7920

In this post I will show you how to find files that are larger than a specific size in a folder and all its sub-subfolders. My choice of command line utilities for this operation is going to be the built-in PowerShell and Command Prompt.

Windows PowerShell

The following command will find and list all files that are larger than 500MB in the entire C:\ drive.

Get-ChildItem C:\ -recurse | where-object {$_.length -gt 524288000} | Sort-Object length | ft fullname, length -auto

Explanation:

  • -recurse parameter is used to find files stored in all sub-directories recursively. To find files only in the main folder you can remove this parameter.
  • where-object {$_.length -gt 524288000} is our filter. It collects only those files that are greater than 500MB, while ignoring the rest. Size is in bytes. If you’d like to do the opposite, i.e., find files smaller than 500MB, then use the -lt parameter.
  • Sort-Object length sorts result in ascending (default) order by length. To sort in descending order use this: Sort-Object length -descending.
  • ft fullname, length -auto: ft or Format-Table is used to format the result. -auto prevents the output from spreading to the full width of the window, and consequently making the result easier to read. Run get-childitem | get-member to see other properties.

If you’re interested only in a specific file type, specify it this way in the command:

Get-ChildItem C:\ -recurse -include *.exe

Windows Command Prompt

In Command Prompt, forfiles command is used for batch processing a command on a file or set of files. The following command will find and list all files that are larger than 500MB in the C:\ drive.

forfiles /P C:\ /M *.* /S /C "CMD /C if @fsize gtr 524288000 echo @PATH @FSIZE"

Explanation:

  • /P (Path): Specifies the path to process. If ignored, process starts in the current working directory.
  • /M (Mask): Specifies the search filter. Example, for executables use *.exe.
  • /S (Sub-Directories): Search for files in sub-directories recursively.
  • /C (Command): Runs the specified command enclosed in quotation marks on each file.
  • @PATH: Is a variable. It shows the full path of the file.
  • @FSIZE: Shows the file size, in bytes.

To see list of other parameters and variables, simply enter forfiles /? in the command-line. This will help you to expand and format the output.


Tweet

Related posts:

  • Batch Rename File Extensions with Command Prompt / PowerShell
  • Recursively Delete a Specific File Type from all Subfolders
  • Delete Files Based on Extension, Attribute in Folders & Subfolders
  • Create Mozilla Firefox Desktop Shortcuts to Specific Profiles
  • Flatten Folder Structure, Move Files from Sub-Folders to Main
Categories: Tips 'n Tricks | Tags: Command Prompt, PowerShell
Adobe Reader: Change Text, Background Color for Eye-Friendly Reading
Delete Files Older Than X Days in Windows with PowerShell & CMD

  • Get Updates via Email

  • Recent Posts

    • CMS2CMS: Migrate Site from Drupal or Joomla to WordPress
    • WordPress: Add Preview Button in Distraction Free Writing
    • How to Activate or Deactivate Individual Jetpack Modules
    • Windows 8: Auto Update Defender with Windows Update Disabled
    • Automatically Start and Close Programs at Specific Time
    • How to Copy Code from Notepad++ with Syntax Highlighting
  • Random Posts

    • Refer a Candidate and Google India Might Pay You 100,000 INR
    • Create Presentations Online with SlideRocket
    • Recursively Delete a Specific File Type from all Subfolders
    • Foursquare Venue Page Photos "Hacked"
    • Download Videos Without Using Extensions
    • Write Email in Markdown on Chrome, Firefox, and Thunderbird
  • Categories

    • Blogging
    • Games
    • Google
    • How To?
    • Linux
    • Microsoft
      • Windows
    • Miscellaneous
    • Phone
    • Snippets
      • AutoHotkey Snippets
      • CSS Snippets
      • htaccess Snippets
      • JavaScript Snippets
      • PowerShell Snippets
      • WordPress Snippets
    • Social
    • Software
      • Browsers
    • Tips 'n Tricks
    • Wallpapers
    • Web
© SumTips. Contact | Sitemap | Privacy Policy