Master the command line: Deleting files and folders

When it comes to quickly taking care of daily tasks, the command line can be both powerful and dangerous. Take today’s commands as an example: the rm command allows you to remove (or delete) files. The rmdir command does the same to directories (also know as folders). But be careful: unlike when you move files to the Trash from the Finder, there’s no way to get them back if you use these commands. Still, if you want to tap into Terminal’s powers, this is a command you can’t overlook. I’ll show you how to add a safeguard to ensure that you only delete files you really want to delete.

Why bother deleting files with the command line?

Deleting files with the Finder isn’t too difficult, plus you can always fish files out of the Trash if you change your mind. So why bother using the command line? Here are some reasons:

You can delete multiple files quickly and efficiently using wildcards.
You can remove files from the Trash when you encounter stubborn errors.
You can delete files that are hidden in the Finder; these files, which can contain settings for certain apps or parts of OS X, contain a dot (.) before their names and the Finder doesn’t show them.
If you’ve lost access to the Finder because your Mac is on the blink, you might be able to use the command line to troubleshoot the problem.

Delete files

It’s dangerously easy to delete files with the rm command. Here’s an example. After you launch Terminal (in your /Applications/Utilities folder) type cd ~/Desktop to navigate to the Desktop directory. If you had a file here named MyFile.rtf that you never, ever wanted to see again, you could run this command:

rm MyFile.rtf

To read this article in full or to leave a comment, please click here