rm
rm
: remove files or directories.
The rm
command is used to delete files and directories from the filesystem. Because it directly removes files without sending them to a "trash" or "recycle bin," it's a powerful but potentially dangerous tool. Once a file is deleted using the rm
command, recovering it can be difficult or impossible, especially on systems without a dedicated backup solution.
Be very careful when using the rm
command, especially with the -r
(recursive) or -f
(force) options, as it permanently deletes files and directories without sending them to the recycle bin or trash. Double-check the file or directory names before running the command to avoid accidentally deleting important data.
If you're not sure, use the -i
(interactive) option when deleting multiple files or directories to prompt for confirmation before each removal. This can help prevent accidental deletions.
Remember that you can use the Tab key to autocomplete file and directory names in the terminal.
For example, you can type rm f
and then press Tab to autocomplete the command to rm file.txt
. This is a great way to avoid typos and speed up your work.
Examples
Linux/macOS
Delete a single file:
rm file.txt
Delete multiple files:
rm file1.txt file2.txt file3.txt
Delete a directory and its contents:
rm -r path/to/directory
Forcefully delete a directory without prompts or warnings. Bypass write protection. Don't show errors if the file/directory doesn't exist:
rm -rf path/to/directory
Delete files in interactive mode (ask for confirmation before each file deletion):
rm -i path/to/file.txt
Windows (PowerShell)
In Windows PowerShell, the equivalent command to rm
is Remove-Item
. The behavior and options are similar to Unix systems.
Remove a single file in Windows PowerShell:
rm file.txt
Remove multiple files in Windows PowerShell:
rm file1.txt, file2.txt
Remove an empty directory:
rm -Path path\to\empty_directory
Remove a non-empty directory and its contents recursively:
rm -Path path\to\directory -Recurse
Force removal without prompting for confirmation:
rm -Path path\to\file.txt -Force
Prompt for confirmation before removing each file:
rm -Path path\to\file.txt -Confirm
Hi! I'm Alex, creator of GitByBit.
And this is Gitopedia—a reference that summarizes knowledge in my Git course.
Gitopedia is designed to be a personal knowledge base. When you progress through the main Git course in VS Code, you unlock all of these topics, one by one, bit by bit. This gives you time to digest the information and gradually build the mental model of Git. Here's an example of how it works:
Learning directly in VS Code lets you practice Git exactly as you would in real life, doing real jobs, writing real code. In addition, the course has access to your actual terminal, so it can point out mistakes, suggest workarounds, etc.
The course is FREE, there are no Ads or other bullshit. There are optional premium add-ons you can purchase, mainly to support my work (regrettably, I have to eat every day), but that's totally up to you.