Summary
- > Why delete files with the command line?
- > Permanently delete files
- > Permanently delete empty folders
- > Delete folders and subfolders
- > Delete one or more locked documents
When you drag and drop a folder into your Mac's Trash, it doesn't actually erase itself. It remains on the hard drive.
To delete it irretrievably, you must use the command line of your Mac (Terminal). The technique is simple but risky since it will be impossible for you to recover it.
If, however, you want to use the Terminal, then follow this tutorial. We use orders rm (diminutive of remove, remove in Spanish) and rmdir (dir for directory, folder) to delete one or more items.
Why delete files with the command line?
Deleting files through the Finder is not permanent because it is always possible to restore them. Sometimes it is more convenient to go through the command line, here are the different scenarios:
- Delete multiple files quickly and efficiently, then they will be unrecoverable.
- Delete documents from the Recycle Bin when you encounter persistent errors.
- Delete hidden files in Finder. They may contain settings for certain applications and the Finder does not display them.
- If you lost access to the Finder due to a malfunction in your Mac.
Permanently delete files
It is dangerously easy to delete files with the command rm. Here's how:
- Open the Port (Finder → Applications → Utilities).
- type cd ~ / Desktop to go to the Desktop directory. (To type the tilde, press the keys alt to the left of the keyboard and N.)
- Press Starter.
Warning: for each command, you must respect spaces, upper and lower case letters and type the extension of your document (here, rtf).
To delete your file, enter the command, rm [nomdufichier].rtf
Once, the key Starter pressed, the file will be permanently deleted, without you being able to recover it.
If you want to delete multiple items, type:
- rm [nomdufichier].rtf [nomdufichier].rtf [nomdufichier].rtf.
- Then confirm by pressing Starter.
To avoid deleting files in a hurry, Apple has created a command, which requires deletion confirmation for each file.
For this you need to type -i before your file name: rm -i [nomdufichier].rtf.
To delete multiple documents, enter: rm -i [nomdufichier].rtf [nomdufichier].rtf [nomdufichier].rtf.
When you go to press Starter, the command rm will not activate, -i will act as a pause button.
It will then be displayed remove Turo.rtf?. To confirm type yes ou Y.
Permanently delete empty folders
Deleting folders or directories is slightly different.
To execute the command rm on a directory, you will need to enter cd ~ / Desktop, type Starter, then enter rmdir.
Note that this command only serves to delete empty directories.
In our example, we want to offload a directory named empty folder, so we type rmdir emptyfolder.
Note that you cannot use -i with the order rmdir, 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 Terminal to delete your folder but also all the files and subfolders it contains. Remember that this deletion is permanent.
Type: rm -r [nomdufichier]
Delete one or more locked documents
If you are unable to empty the Trash on your Mac, a file is locked or you do not have permission to delete files, then you can use the command rm -R.
Entrez rm -R, add a space, then drag and drop the file(s) into the Trash into the Terminal window.
You will see displayed files with a path such as: /Users/[lenomdevotremac]/.Trash/[nomdufichier].[extensiondufichier]
When you're ready, all you have to do is press Starter.