Delete Batches Of Files Faster With The Command Line

Want to clear up some space on your drive? You can make the process much easier by using the command line. Here's how to do it for Windows and Mac users.

Bin picture from Shutterstock

Using the command prompt (Windows) or terminal (Mac) is especially useful if you want to delete files of a particular format or type. The basic command used is del for Windows, and rm for Macs.

On Windows, to open the command prompt, type Windows-R to bring up the Run dialog, type cmd into the dialog, then hit Enter. If you want to make sure that you're in a specific directory, Shift-right click and choose 'Open command window here'. On Mac, hit Command-Space to access spotlight and type 'Terminal'.

ITo delete an individual file in the current directory, just type the command followed by the name of the file:

del IHateThisFile.txt (Windows)

rm IHateThisFile.txt (Mac)

You can also specify multiple files by separating their names with spaces. However, for individual files, you're probably better off staying in Explorer or Finder.

Things get interesting when you start introducing wildcards, using the * symbol. Let's say you want to delete any item in a folder that starts with the word Pineapple. You could use this command to delete them all very quickly:

del Pineapple* (Windows)

rm Pineapple* (Mac)

You can do the same for specific file types.

del *.jpg (Windows)

rm *.jpg (Mac)

Wildcards can wipe out lots of files really fast and save you a lot of time.

These commands have lots of other tweaks you can use to target files. In Windows, type del /? to see all the alternatives you can use. On Mac, type man rm for a similiar list.

Lifehacker 101 is a weekly feature covering fundamental techniques that Lifehacker constantly refers to, explaining them step-by-step. Hey, we were all newbies once, right?

WATCH MORE: Tech News & Life Hacks


    I'm a command line junkie from way back, but I'm not sure why doing a del is quicker than searching a folder in windows, selecting, and then deleting.

    Especially given most people barely understand command lines, and directories etc.

      By that logic you can argue anything people don't understand as slower than something they do understand. It's even less relevant a comment on an article which is obviously targeted at people who "barely understand command lines", because it's a very basic usage example.

      Quick example based on something I had to do this morning. Deleting all the old output files from a directory. Tell me which is faster. The way I did it via command line:

      WIN+~ (console shortcut)
      del e:\s{tab}fe{tab}{tab}\f{tab}\bin\d{tab}\*.bak.* [Enter]

      or doing it with the GUI:

      WIN+R (run shortcut)
      e:\source\ferretlib.reporting\ferretlib.reporting\bin\debug\ [Enter]
      CTRL + F (find shortcut)
      *.bak.* [Enter]
      Click in results pane
      CTRL+A (select all shortcut)
      Y (for "Yes" at confirm delete dialog)

      Even then, the second one is only as short as it is based on assumed knowledge of how Explorer works.

      You do the math.

    "RD /S /Q" is really good for removing entire directory structures. Much faster than windows, also can delete nuisance files too.

    If you're going to do "del" with any form of wildcard, then first do a "dir" with the same structure,
    e.g. "dir *.do?" before "del *.do?"
    That way you can see exactly what you're about to delete. This has saved me from many a mistake (admittedly I'm going back 15 years or more).

    the Mac commands will also work on pretty much any linux/unix/bsd (including android)

      You mean the unux commands happen to work on POSIX compliant systems?

    Windows (NTFS) users, Everything by Void Tools.
    Set up a keyboard shortcut (in my case Ctrl+Tilde), start typing fragments of file paths for example (\p es\ ws\ .h shows me all the .h in my C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include folder), select some or all, and hit delete.
    Nice easy gui, faster to find things than command line (especially if you don't instantly remember the whole path), it's seriously a tool everybody should use.

    If you're in a situation on Linux/Mac where files have accumulated to the point where you have a huuuuge number of files to delete, I discovered the quickest method (by a factor of 5) is to use rsync. Create an empty directory and use the following:

    rsync -a --delete emptydirectory/ huugedirectory/

    Heaps faster than rm -rf.

Join the discussion!