Equivalent of rm and mv in windows .cmd
Solution 1:
move
in windows is equivalent of mv
command in Linux
del
in windows is equivalent of rm
command in Linux
UPDATE: This is a simplified answer but the behavior and capabilities are quite different as mentioned by @WestCoastProjects in the comment.
Solution 2:
move
and del
ARE certainly the equivalents, but from a functionality standpoint they are woefully NOT equivalent. For example, you can't move both files AND folders (in a wildcard scenario) with the move
command. And the same thing applies with del
.
The preferred solution in my view is to use Win32 ports of the Linux tools, the best collection of which I have found being here.
mv
and rm
are in the CoreUtils package and they work wonderfully!
Solution 3:
If you want to see a more detailed discussion of differences for the commands, see the Details about Differences section, below.
From the LeMoDa.net website1 (archived), specifically the Windows and Unix command line equivalents page (archived), I found the following2. There's a better/more complete table in the next edit.
Windows command Unix command
rmdir rmdir
rmdir /s rm -r
move mv
I'm interested to hear from @Dave and @javadba to hear how equivalent the commands are - how the "behavior and capabilities" compare, whether quite similar or "woefully NOT equivalent".
All I found out was that when I used it to try and recursively remove a directory and its constituent files and subdirectories, e.g.
(Windows cmd)>rmdir /s C:\my\dirwithsubdirs\
gave me a standard Windows-knows-better-than-you-do-are-you-sure message and prompt
dirwithsubdirs, Are you sure (Y/N)?
and that when I typed Y
, the result was that my top directory and its constituent files and subdirectories went away.
Edit
I'm looking back at this after finding this answer. I retried each of the commands, and I'd change the table a little bit.
Windows command Unix command
rmdir rmdir
rmdir /s /q rm -r
rmdir /s /q rm -rf
rmdir /s rm -ri
move mv
del <file> rm <file>
If you want the equivalent for
rm -rf
you can use
rmdir /s /q
or, as the author of the answer I sourced described,
But there is another "old school" way to do it that was used back in the day when commands did not have options to suppress confirmation messages. Simply
ECHO
the needed response and pipe the value into the command.
echo y | rmdir /s
Details about Differences
I tested each of the commands using Windows CMD and Cygwin (with its bash
).
Before each test, I made the following setup.
Windows CMD
>mkdir this_directory
>echo some text stuff > this_directory/some.txt
>mkdir this_empty_directory
Cygwin bash
$ mkdir this_directory
$ echo "some text stuff" > this_directory/some.txt
$ mkdir this_empty_directory
That resulted in the following file structure for both.
base
|-- this_directory
| `-- some.txt
`-- this_empty_directory
Here are the results. Note that I'll not mark each as CMD or bash
; the CMD will have a >
in front, and the bash
will have a $
in front.
A big thanks to @JillAndMe for the comment,
Note you must
you[use] "/" not this: "\" [;]rmdir
for delete foldersdel
for files
Changes have been made accordingly, and an example for del
and rm
has been added.
DEL and RM
(for files). As far as I know, these work identically.
>del this_directory\some.txt
>tree /a /f
Folder PATH listing for volume Windows
Volume serial number is ████████ ████:████
base
+---this_directory
\---this_empty_directory
$ rm this_directory/some.txt
$ tree --charset=ascii
base
|-- this_directory
`-- this_empty_directory
2 directories, 0 files
RMDIR
>rmdir this_directory
The directory is not empty.
>tree /a /f .
Folder PATH listing for volume Windows
Volume serial number is ████████ ████:████
base
+---this_directory
| some.txt
|
\---this_empty_directory
> rmdir this_empty_directory
>tree /a /f .
base
\---this_directory
some.txt
$ rmdir this_directory
rmdir: failed to remove 'this_directory': Directory not empty
$ tree --charset=ascii
base
|-- this_directory
| `-- some.txt
`-- this_empty_directory
2 directories, 1 file
$ rmdir this_empty_directory
$ tree --charset=ascii
base
`-- this_directory
`-- some.txt
RMDIR /S /Q and RM -R ; RM -RF
>rmdir /s /q this_directory
>tree /a /f
base
\---this_empty_directory
>rmdir /s /q this_empty_directory
>tree /a /f
base
No subfolders exist
$ rm -r this_directory
$ tree --charset=ascii
base
`-- this_empty_directory
$ rm -r this_empty_directory
$ tree --charset=ascii
base
0 directories, 0 files
$ rm -rf this_directory
$ tree --charset=ascii
base
`-- this_empty_directory
$ rm -rf this_empty_directory
$ tree --charset=ascii
base
0 directories, 0 files
RMDIR /S and RM -RI
Here, we have a bit of a difference, but they're pretty close.
>rmdir /s this_directory
this_directory, Are you sure (Y/N)? y
>tree /a /f
base
\---this_empty_directory
>rmdir /s this_empty_directory
this_empty_directory, Are you sure (Y/N)? y
>tree /a /f
base
No subfolders exist
$ rm -ri this_directory
rm: descend into directory 'this_directory'? y
rm: remove regular file 'this_directory/some.txt'? y
rm: remove directory 'this_directory'? y
$ tree --charset=ascii
base
`-- this_empty_directory
$ rm -ri this_empty_directory
rm: remove directory 'this_empty_directory'? y
$ tree --charset=ascii
base
0 directories, 0 files
<s>I'M HOPING TO GET</s> ANYONE IS WELCOME TO ANSWER WITH A MORE THOROUGH "MOVE AND MV" TEST
Notes
- I know almost nothing about the LeMoDa website, other than the fact that the info is
Copyright © Ben Bullock 2009-2018. All rights reserved.
(archived copyright notice)
and that there seem to be a bunch of useful programming tips along with some humour (yes, the British spelling) and information on how to fix Japanese toilets. I also found some stuff talking about the "Ibaraki Report", but I don't know if that is the website.
I think I shall go there more often; it's quite useful. Props to Ben Bullock, whose email is on his page. If he wants me to remove this info, I will.
I will include the disclaimer (archived) from the site:
Disclaimer Please read the following disclaimer before using any of the computer program code on this site.
There Is No Warranty For The Program, To The Extent Permitted By Applicable Law. Except When Otherwise Stated In Writing The Copyright Holders And/Or Other Parties Provide The Program “As Is” Without Warranty Of Any Kind, Either Expressed Or Implied, Including, But Not Limited To, The Implied Warranties Of Merchantability And Fitness For A Particular Purpose. The Entire Risk As To The Quality And Performance Of The Program Is With You. Should The Program Prove Defective, You Assume The Cost Of All Necessary Servicing, Repair Or Correction.
In No Event Unless Required By Applicable Law Or Agreed To In Writing Will Any Copyright Holder, Or Any Other Party Who Modifies And/Or Conveys The Program As Permitted Above, Be Liable To You For Damages, Including Any General, Special, Incidental Or Consequential Damages Arising Out Of The Use Or Inability To Use The Program (Including But Not Limited To Loss Of Data Or Data Being Rendered Inaccurate Or Losses Sustained By You Or Third Parties Or A Failure Of The Program To Operate With Any Other Programs), Even If Such Holder Or Other Party Has Been Advised Of The Possibility Of Such Damages.
- Actually, I found the information with a Google search for "cmd equivalent of rm"
https://www.google.com/search?q=cmd+equivalent+of+rm
The information I'm sharing came up first. Given the way Google is personalized and continuously updated, your search results might be quite different.