‘rm’ is not recognized as an internal or external command – Solved

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?

The 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.

The word rm stands for remove and on Windows, we can use its equivalent command i.e del.

How to solve “rm is not recognized as an internal or external command” in Windows

The 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:

  1. Use of the del command in Windows
  2. Use of Powershell to use the rm command in Windows
  3. Use of third-party software like Git Bash.

Solution 1: Use of the del command in Windows

Since 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 rd or rmdir command to remove empty directory in Windows through Command Prompt (CMD). Example:

rmdir myfolder

#or

rd myFolder

The rmdir or rd only 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 rm command.

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:

rm myfile.txt

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:

Remove-Item myfile.txt

To delete a folder and its sub-folders you can also use the Remove-Item command like this:

Remove-Item Myfolder

It will ask for confirmation to delete the folder and its children (files and sub-folders) inside the Myfolder.

rm is not recognized as an internal or external command

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 command.

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“.

rm is not recognized as an internal or external command

Now in the terminal use the command:

rm myfile.txt

rm is not recognized as an internal or external 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.

Conclusion

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 rm.


Related Article:

Solving “npm not recognized as an internal or external command” Error

Scroll to Top