Delete Batches Of Files Faster With The Command Line

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?


The Cheapest NBN 50 Plans

Here are the cheapest plans available for Australia’s most popular NBN speed tier.

At Lifehacker, we independently select and write about stuff we love and think you'll like too. We have affiliate and advertising partnerships, which means we may collect a share of sales or other compensation from the links on this page. BTW – prices are accurate and items in stock at the time of posting.

Comments


9 responses to “Delete Batches Of Files Faster With The Command Line”