How to permanently delete a file with the terminal?

When you drag and drop a folder in the Recycle Bin on your Mac, it does not really disappear. It remains on the hard drive.

To remove it irretrievably, you must use the command line of your Mac (Terminal). The technique is simple but risky since you will not be able to recover it.

If, however, you want to use the Terminal, then follow this tutorial. We use the commands rm (diminutive of remove, delete in French) and rmdir (dir for the directory, folder) to delete one or more elements.

Why delete files with the command line?

The deletion of files via the Finder is not definitive because it is always possible to restore them. Sometimes it is more convenient to go through the command line, here are the different cases:

  • Delete multiple files quickly and efficiently, they will be unrecoverable.
  • Delete documents from the Recycle Bin when you encounter persistent errors.
  • Delete hidden files in the Finder. They may contain settings for some applications and the Finder does not display them.
  • If you lost access to the Finder due to a malfunction on your Mac.

Permanently delete files

It is dangerously easy to delete files with the rm command. Here’s how to proceed:

  • Open the Terminal (Finder → Applications → Utilities).
  • Type cd ~ / Desktop to go to the Desktop directory. (To type the tilde, press the alt keys on the left of the keyboard and N. )
  • Press Enter.


Attention: for each command, you will have to respect spaces, capital letters, lowercase letters and type the extension of your document (here, rtf).

To clear your file, enter the command, rm [filename] .rtf

Once the Enter key is pressed, the file will be permanently deleted, without you being able to recover it.

If you want to delete multiple items, type:

  • rm [filename] .rtf [filename] .rtf [filename] .rtf .
  • Then, confirm by pressing Enter.

    istock 453158651 permanently delete one of the files mac termial rm

To avoid erasing files in a hurry, Apple has created a command, which requires a delete confirmation for each file.

To do this, you must type -i before the name of your file: rm -i [filename] .rtf.

Permanently delete empty folders

Deleting folders or directories is slightly different.

To run the rm command on a directory, you will need to enter cd ~ /Desktop, type Enter, and then enter rmdir.

Note that this command only serves to erase empty directories.

In our example, we want to unload ourselves from a repertoire named folder, so we type rmdir dossiervide.

Be aware that you can not use -i with the rmdir command, so it is very risky.

To delete full directories, read the following.

Delete folders and subfolders

When you add -R or -r (for recursive option) to your rm command, you ask the Terminal to erase your folder but also all the files and subfolders it contains. Remember that this deletion is permanent.

Type: rm -r [filename]