In relation to rapidly taking good care of every day duties, the command line may be each highly effective and harmful. Take the instructions on this article for instance: the rm
command lets you take away (or delete) information. The rmdir
command does the identical to directories (also referred to as folders). However watch out: In contrast to whenever you transfer information to the Trash from the Finder, there’s no method to get them again if you happen to use these instructions.
Nonetheless, if you wish to faucet into Terminal’s powers in macOS Sonoma or older variations, it is a command you’ll be able to’t overlook. I’ll present you the right way to add a safeguard to make sure that you solely delete information you actually need to delete.
Why hassle deleting information with the command line?
Deleting information with the Finder isn’t too troublesome, plus you’ll be able to at all times fish information out of the Trash if you happen to change your thoughts. So why hassle utilizing the command line? Listed here are some causes:
- You need to use wildcards to delete a number of information rapidly and effectively.
- You may take away information from the Trash whenever you encounter cussed errors.
- You may delete information which might be hidden within the Finder. These information, which may include settings for sure apps or components of macOS, include a dot (.) earlier than their names and the Finder doesn’t present them.
- In the event you’ve misplaced entry to the Finder as a result of your Mac is on the blink, you would possibly be capable of use the command line to troubleshoot the issue.
How you can delete information
It’s dangerously simple to delete information with the rm
command. Right here’s an instance. After you launch Terminal (in your /Purposes/Utilities folder) kind cd ~/Desktop
to navigate to the Desktop listing. To delete a file on the Desktop, kind rm filename
, changing filename
with the precise identify of the file you need to delete. (If in case you have a file identify with areas, it’s worthwhile to put the identify in quotes: "For Instance.txt"
.) In the event you had a file right here named MyFile.rtf that you just by no means, ever needed to see once more, you could possibly run this command:
rm MyFile.rtf
While you press Return, the file will go poof! The Mac doesn’t affirm if you wish to delete the file. It will likely be gone, toast, historical past. You may’t get it again.
You may even delete a number of information in a single command. If in case you have three information in your Desktop that you just need to delete, and also you need to delete them suddenly, you are able to do so like this (when you have a file identify with areas, it’s worthwhile to put the identify in quotes: "For Instance.txt"
.):
rm MyFile.rtf MyCV.rtf MyGreatAmericanNovel.rtf
Once more, urgent the Return key does the soiled work.
A security web
It’s price repeating: this command deletes information. It nukes them. You may’t get them again. You may’t click on on the Trash icon and retrieve information you’ve by accident deleted.
However there’s a security web: it’s the -i
(interactive) flag. So if you happen to’re feeling cautious, you could possibly run the above instructions with this flag as follows:
rm -i MyFile.rtf
Or, within the case of deleting a number of information:
rm -i MyFile.rtf MyCV.rtf MyGreatAmericanNovel.rtf
In every case, urgent Return gained’t really activate the rm
command, as a result of the -i
flag acts as a pause button. You’ll see the next in Terminal when working these instructions:

IDG
In an effort to proceed, it’s worthwhile to kind sure
, or just y
. Within the case of a number of information, you’ll see one question for every file. Granted, it’s simple to get into the behavior of rapidly typing y
, however the query is meant to make you cease and assume very rigorously about whether or not you actually need to delete that file.
How you can delete empty directories (a.okay.a folders)
Deleting directories, or folders, is a bit totally different. In the event you attempt to run the rm
command on a listing, you’ll see the next message:

You may’t delete a listing utilizing the rm command.
IDG
There’s a particular command for deleting directories: rmdir
. So to delete a listing named Archives, run this command (If in case you have a listing identify with areas, it’s worthwhile to put the identify in quotes: "For Instance"
.):
rmdir Archives
You may’t use the -i
flag with the rmdir
command, so the command is a bit riskier.
Notice that this command solely deletes empty directories. If you wish to delete a listing and the information it accommodates, learn on.
How you can delete all the pieces in a listing
The rm
command has a robust possibility, -R
(or -r
), in any other case often known as the recursive possibility. While you run the rm -R
command on a folder, you’re telling Terminal to delete that folder, any information it accommodates, any sub-folders it accommodates, and any information or folders in these sub-folders, all the way in which down. You enter the command as rm
-R directoryname
, the place you substitute directoryname
for the identify of the listing you need to delete. (If in case you have a listing identify with areas, it’s worthwhile to put the identify in quotes: "For Instance"
.)
For instance, let’s say you will have a listing filled with archives, containing sub-directories and information. Deleting every merchandise individually from the Finder or the command line can take a very long time. So simply run the command like this:
rm -R Archives
Bear in mind, this deletion is remaining. However you should use the -i
flag for defense:
rm -iR Archives
It will ask you to verify the deletion of every merchandise. This may be annoying, however until you’re actually positive you need to delete all these information, it’s most likely finest to be protected.
Can’t empty Trash within the Finder? Use the Terminal
When can the rm -R
command turn out to be useful? Say you’ll be able to’t empty the Trash in your Mac. A file is likely to be locked or it’s possible you’ll not have permission to delete a number of information. This type of glitch is annoying, however you should use the command line to supply a simple answer.
In Terminal, kind the next:
rm -R
Then kind an area.
Within the Finder, open the Trash, after which drag the objects it accommodates to the Terminal window. You’ll see a number of information with paths equivalent to /Customers/.Trash/file.txt.
If there are many information, it’s possible you’ll discover that the ensuing record—all on one lengthy line, wrapping within the Terminal window—could also be very lengthy. In the event you’re completely positive that you just need to delete all these things, press Return. Terminal will empty the Trash. Command line win!

IDG
Wish to study extra? See our articles about navigating the file system with the command line, studying from man pages, and copying and transferring information.