If you are a Windows user and trying to use “rm” command to remove a file or folder then you will encounter the “rm is not recognized as an internal or external command” error in your terminal/command prompt. This error occurs when we try to use the rm command and the command is not available in the Windows Operating system.
In this article, we will discuss this error and learn about different alternative commands to use rm in Windows OS and also how can we use
rm command in Windows.
What is the rm command?
rm command is a Unix-based command used in Linux and Mac OS to remove or delete files and directories from the command line interface.
rm stands for remove and on Windows, we can use its equivalent command i.e
How to solve “rm is not recognized as an internal or external command” in Windows
rm command is not available in Windows OS by default and you cannot use it from your command prompt interface. Attempting to use it will give us the “‘rm’ is not recognized as an internal or external command” error.
However, here are three ways we can use
rm or use its equivalent command in Windows to delete or remove files or directories:
- Use of the del command in Windows
- Use of Powershell to use the rm command in Windows
- Use of third-party software like Git Bash.
Solution 1: Use of the del command in Windows
rm command is not available in Windows OS, we can use its Windows equivalent command i.e the
del command to remove or delete files and folders.
For example, let’s say we have a file name example.txt in a folder, so to delete it we have to run:
# delete single file del example.txt #to delete an entire folder del "D:exams folder"
Make sure to put the folder name in double quote if the name has white space in between.
The above command will delete the file from the folder.
You can also use
rmdir command to remove empty directory in Windows through Command Prompt (CMD). Example:
rmdir myfolder #or rd myFolder
rdonly works if the folder you are trying to delete is empty.
Solution 2: Use Powershell to use rm command in Windows
Now if you are using PowerShell in windows then you can easily delete any file or folder using the
For example, you have a file name myfile.txt in the folder named demo.
Now, go to that specific folder and hold
Shift button, and right-click inside the folder. Click on “Open PowerShell window here“.
And now we can use the rm command inside the PowerShell terminal like this:
You can also use the “Remove-Item” command as an alternative to rm command in PowerShell to delete files and folders.
For example, use the
Remove-Item command to delete a file like this:
To delete a folder and its sub-folders you can also use the
Remove-Item command like this:
It will ask for confirmation to delete the folder and its children (files and sub-folders) inside the Myfolder.
Press Y to delete all.
If you want to delete it in one go without any confirmation message then use the
-Recurse option with the
Remove-Item Myfolder -Recurse
This will delete the directory and all its files and sub-directories without any confirmation message.
Solution 3: Use third-party software like Git Bash
In Windows, we can use third-party tools or software like Git Bash to use rm command in Windows.
This tools provides a Unix-like environment on windows and includes linux-based commands like
rm with it.
To use the rm command in Windows using Git Bash, follow these steps:
Step 1: Download and install git Bash for windows from Git Site
Install Git Bash with all it’s default setting.
Step 2: Once installation is completed, you can use gitbash terminals in your WIndows OS.
To delete a file using Git Bash, just go to the specific folder and right-click inside the folder (File Explorer) and click on “Git Bash Here“.
Now in the terminal use the command:
This will delete the file from the folder.
Important: The command rm, del, Remove-Item or rmdir will delete the files and folders permanently from the computer. You can not restore it from the Recycle Bin.
Here, we have discussed about the “‘rm’ is not recognized as an internal or external command” error and how to solve the error in Windows Operating System.
The main cause of the error is that
rm is Unix based command which is not available for Windows OS. And to solve it we can use the windows equivalent of rm i.e
del command, use Powershell to use rm in windows, or download and install Git Bash tool to use