Friday, January 3, 2014

Delete Batches of Files Faster with the Command Line


Sometimes your files have overstayed their welcome and they just need to go and you want them to go as fast as possible. Or you just want to delete everything that starts with a certain word. Or some files refuse to go into the trash/recycling bin. Let the command line come to your rescue. Deleting files doesn't take much effort. All you need is the rm command. For example: rm IHateThisFile.txt You can also specify multiple files by separating their names with spaces. If you have a folder, you can add the -r flag for a recursive delete (i.e. getting rid of everything in the folder and its sub-folders) like so: rm -r IHateThisFolder You can also remove directories with rmdir instead, but the -r flag should give you less grief and just get the job done. Those are the basics, however, and you can do all of that without the terminal just as easily. Things get interesting when you start introducing wildcards. 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: rm -r Pineapple* You can do the same for certain types of files, like JPEGs: rm -r *.jpg Wildcards can wipe out lots of files really fast and save you a bunch of time. (You don't have to use the -r flag in all cases, by the way, but I like to because then I know everything will get deleted and I don't have to think twice about it.) Next time you need to get rid of a batch of files, turn to the terminal instead of sorting through them all yourself.

No comments:

Post a Comment