除了进度之外,如何在命令行中使 robocopy 保持静默?

发布于 2024-09-26 19:00:15 字数 137 浏览 0 评论 0原文

我正在使用 robocopy 通过 PowerShell 脚本进行备份,它非常棒,只是我希望它在复制时仅显示进度百分比,而不显示所有其他信息。

其他信息使命令窗口变得混乱,我将其清理干净,以便可以轻松查看备份的整体进度。

这可能吗?

I'm using robocopy to do backups with a PowerShell script, and it's pretty awesome, except that I'd like it to only show the progress percentage while it copies and not all of the other information.

The other information clutters the command window, which I'd clean and simple so that it's easy to see the overall progress of the backup.

Is this possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

对你的占有欲 2024-10-03 19:00:15

我添加了以下2个参数:
/np /nfl

因此,结合 AndyGeek 答案中的 5 个参数,即 /njh /njs /ndl /nc /ns,您将得到以下内容无声无息:

ROBOCOPY [source] [target] /NFL /NDL /NJH /NJS /nc /ns /np

/NFL : No File List - don't log file names.
/NDL : No Directory List - don't log directory names.
/NJH : No Job Header.
/NJS : No Job Summary.
/NP  : No Progress - don't display percentage copied.
/NS  : No Size - don't log file sizes.
/NC  : No Class - don't log file classes.

I added the following 2 parameters:
/np /nfl

So together with the 5 parameters from AndyGeek's answer, which are /njh /njs /ndl /nc /ns you get the following and it's silent:

ROBOCOPY [source] [target] /NFL /NDL /NJH /NJS /nc /ns /np

/NFL : No File List - don't log file names.
/NDL : No Directory List - don't log directory names.
/NJH : No Job Header.
/NJS : No Job Summary.
/NP  : No Progress - don't display percentage copied.
/NS  : No Size - don't log file sizes.
/NC  : No Class - don't log file classes.
不美如何 2024-10-03 19:00:15

我通过使用以下选项来做到这一点:

/njh /njs /ndl /nc /ns

请注意,文件名仍然显示,但这对我来说很好。

有关 robocopy 的详细信息,请访问 https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy

I did it by using the following options:

/njh /njs /ndl /nc /ns

Note that the file name still displays, but that's fine for me.

For more information on robocopy, go to https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy

噩梦成真你也成魔 2024-10-03 19:00:15

如果您根本不想输出,这是最简单的方法:

robocopy src dest > nul

如果您仍然需要一些信息并且只想删除部分输出,请使用 R.Koene 答案中的参数。

If you want no output at all this is the most simple way:

robocopy src dest > nul

If you still need some information and only want to strip parts of the output, use the parameters from R.Koene's answer.

一抹苦笑 2024-10-03 19:00:15

在 PowerShell 中,我喜欢使用:

robocopy src dest | Out-Null

它避免了记住所有命令行开关。

In PowerShell, I like to use:

robocopy src dest | Out-Null

It avoids having to remember all the command line switches.

瀟灑尐姊 2024-10-03 19:00:15

robocopy 也倾向于打印空行,即使它不执行任何操作。我使用如下命令过滤掉空行:

robocopy /NDL /NJH /NJS /NP /NS /NC %fromDir% %toDir% %filenames% | findstr /r /v "^$"

robocopy also tends to print empty lines even if it does not do anything. I'm filtering empty lines away using command like this:

robocopy /NDL /NJH /NJS /NP /NS /NC %fromDir% %toDir% %filenames% | findstr /r /v "^$"
欢烬 2024-10-03 19:00:15

如果您希望它完全静默,一种解决方法是将输出重定向到文件(并且可以选择稍后将其删除)。

Robocopy src dest > output.log
del output.log

A workaround, if you want it to be absolutely silent, is to redirect the output to a file (and optionally delete it later).

Robocopy src dest > output.log
del output.log
煮茶煮酒煮时光 2024-10-03 19:00:15

我不确定它是否正确,但我在 Gitlab 中使用了它并且它有效:

robocopy <src> <dst> *.dll *.exe *.bat /E; $LastExitCode

I'm not sure if it is correct but I used this in Gitlab and it works:

robocopy <src> <dst> *.dll *.exe *.bat /E; $LastExitCode
自由如风 2024-10-03 19:00:15

的> null 在引号中不起作用。它看到 > null 作为批处理文件名。

robocopy 没有输出工作!

这是新的批处理文件:

robocopy /mir /B /r:1 /nfl /ndl /njh /njs /nc /ns /np c:\EnvBackup c:\offsite_backup\EnvBackup

robocopy /mir /B /r:1 /nfl /ndl /njh /njs /nc /ns /np c:\shares c:\offsite_backup\shares

robocopy /mir /B /r:1 /nfl /ndl /njh /njs /nc /ns /np c:\Quickbooks_Backup c:\offsite_backup\Quickbooks_Backup

The > null does not work in the quotes. It sees the > null as the batch filename.

The robocopy no output worked!!!

Here is the new batch file:

robocopy /mir /B /r:1 /nfl /ndl /njh /njs /nc /ns /np c:\EnvBackup c:\offsite_backup\EnvBackup

robocopy /mir /B /r:1 /nfl /ndl /njh /njs /nc /ns /np c:\shares c:\offsite_backup\shares

robocopy /mir /B /r:1 /nfl /ndl /njh /njs /nc /ns /np c:\Quickbooks_Backup c:\offsite_backup\Quickbooks_Backup
无妨# 2024-10-03 19:00:15

无需重定向到文件并稍后将其删除。
尝试:

Robocopy src dest > null 

There's no need to redirect to a file and delete it later.
Try:

Robocopy src dest > null 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文