bash 相当于 windows .cmd 中的 rm 和 mv
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17607612/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
equivalent of rm and mv in windows .cmd
提问by user2341103
I have the following in a shell script,I want to convert the following lines into a windows cmd file..can anyone provide inputs on what is the equivalent for "rm" and "mv" in windows cmd file.
我在shell脚本中有以下内容,我想将以下行转换为windows cmd文件..任何人都可以提供有关windows cmd文件中“rm”和“mv”等价物的输入。
rm -f ${BUILD_ID}/${BUILD_ASIC}*rampatch*
mv ${BUILD_ID}/${BUILD_ASIC}*rampatch* ${BUILD_ID}/emul/
回答by Jainendra
move
in windows is equivalent of mv
command in Linux
move
在 Windows 中相当于mv
Linux 中的命令
del
in windows is equivalent of rm
command in Linux
del
在 Windows 中相当于rm
Linux 中的命令
回答by Dave
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
.
move
和del
肯定是等价的,但从功能的角度来看,它们非常不等价。例如,您不能使用该move
命令移动文件和文件夹(在通配符方案中)。同样的事情适用于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.
在我看来,首选的解决方案是使用 Linux 工具的 Win32 端口,我发现这里是最好的集合。
mv
and rm
are in the CoreUtilspackage and they work wonderfully!
mv
并且rm
在CoreUtils包中,它们工作得非常好!
回答by bballdave025
If you want to see a more detailed discussion of differences for the commands, see the Details about Differencessection, below.
如果您想查看有关命令差异的更详细讨论,请参阅下面的“差异的详细信息”部分。
From the LeMoDa.netwebsite1, specifically the Windows and Unix command line equivalentspage, I found the following2. There's a better/more complete table in the next edit.
从LeMoDa.net网站1,特别是Windows 和 Unix 命令行等效页面,我发现了以下内容2。在下一次编辑中有一个更好/更完整的表格。
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".
我很想听听@Dave 和 @javadba 的来信,听听命令的等效性 - “行为和功能”如何比较,无论是非常相似还是“非常不等效”。
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
给了我一个标准的 Windows-knows-better-than-you-are-you-sure 消息和提示
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.
当我输入时Y
,结果是我的顶级目录及其组成文件和子目录消失了。
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
If you want the equivalent for
如果你想要等价的
rm -rf
rm -rf
you can use
您可以使用
rmdir /s /q
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
所需的响应并将值通过管道传输到命令中。
echo y | rmdir /s
echo y | rmdir /s
Details about Differences
差异详情
I tested each of the commands using Windows CMD and Cygwin (with its bash
).
我使用 Windows CMD 和 Cygwin(及其bash
)测试了每个命令。
Before each test, I made the following setup.
在每次测试之前,我进行了以下设置。
Windows CMD
视窗 CMD
>mkdir this_directory
>echo some text stuff > this_directory/some.txt
>mkdir this_empty_directory
Cygwin bash
赛格温 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.
这是结果。请注意,我不会将每个标记为 CMD 或bash
; CMD 将有一个>
在前面,并且bash
将有一个$
在前面。
RMDIR
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 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 AND RM -RI
在这里,我们有一点不同,但它们非常接近。
>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
I'M HOPING TO GET A MORE THOROUGH MOVE AND MV TEST
I'M HOPING TO GET A MORE THOROUGH MOVE AND MV TEST
Notes
笔记
- I know almost nothing about the LeMoDa website, other than the fact that the info is
- 我对 LeMoDa 网站几乎一无所知,除了信息是
Copyright ? Ben Bullock 2009-2018. All rights reserved.
版权?本布洛克 2009-2018 年。版权所有。
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 isthe 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 disclaimerfrom 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"
- 实际上,我通过 Google 搜索“cmd 相当于 rm”找到了信息
https://www.google.com/search?q=cmd+equivalent+of+rm
https://www.google.com/search?q=cmd+equivalent+of+rm
The information I'm sharing came up first.
我分享的信息首先出现。