The terminal is used to perform a number of operations on both Mac and Windows computers such as creating files, to show hidden files, changing the file format and much more. Mac terminal is also used widely for deleting files from the system. The reason why user prefers terminal rather than normal deletion is, when you delete using delete option, the files will go to trash but when you delete with terminal the files won’t go to trash.
Here is how to delete files using Mac terminal:
- Open Mac terminal
- Type rm –Rf
- Drag the file name from Mac desktop into terminal window and then release it
- Or else you can also type file’s destination manually
- Once you type the command, click on return
- Finally, your file will be deleted from desktop
So the full command looks something like this:
rm –Rf /Users/UserName/Desktop/filename
The meaning of ‘rm’ command is to remove, and flag ‘R’ will help you to delete content from a directory. ‘f’ indicates force i.e. it causes the terminal to delete the file. You can skip ‘f’ to avoid error production during deletion process.
To delete directories or folder, follow below command….
There is a separate command to delete directories from Mac machine: rmdir. Let’s take a name of directory or folder is Document, and run the command:
Note: This command is a bit risky as we can’t use –i command with this. And command can only delete empty directories
To delete everything, follow below command…
We have an option in rm command called –R or –r (recursive option). If you run rm command with –R on any folder, you are deleting that folder entirely along with its files, subfolders etc.
Rm –R Document
This will delete the folder permanently. You cannot undo this process nor recover it using the command prompt. If you want to get your data back then make use of this link recover deleted files from Mac terminal. To avoid such data risks you can use –i flag for protection.
Rm –iR Document
If you insert –i in the command then each time it will ask you to confirm before deleting anything. It is the best way to be on a safer side when it comes to data protection.