April 26, 2025
Trending News

A little familiarity with Robocopy, a command-line tool for Windows

  • February 24, 2023
  • 0

Yes good Windows is perceived by the vast majority of the public as an operating system that is used through a graphical interface, this does not mean that

A little familiarity with Robocopy, a command-line tool for Windows

Yes good Windows is perceived by the vast majority of the public as an operating system that is used through a graphical interface, this does not mean that it does not have interesting tools preinstalled or available that work through the command line, the interface whose use is usually associated with Linux.

What’s more, even your own Microsoft takes care of using the command line in Windows without much fuss and it even seems to be giving it more importance recently, something that can be seen from certain points of view as a kind of surrender to the obvious advantages it provides compared to graphical interfaces, even if they are also better in certain ways.

Microsoft has been developing and promoting for many years PowerShell. This command line interpreter was associated with Windows for a long time, but in 2016 the company decided to make it open source (albeit reserving some letters) and port it to Linux and macOS, so since then it has been competing with other solutions in the same field as bash and zsh. One of its advantages over the command line is that it allows you to create your own commands and scripts using the C# programming language.

Help for Robocopy

Help for Robocopy.

The care that the Redmond giant pays to the command line has been palpable of late Windows Terminalan open source terminal application that was set up by default in Windows 11. It is capable of handling the command line (what some colloquially call an MS-DOS emulator) and PowerShell, and can also run separate tabs for WSL, the Windows subsystem for Linux that gives you it allows you to run a full Linux operating system on top of a Microsoft operating system.

As we can see, the command line is far from dead in Windows, and what’s more, given that Microsoft has recently given it a greater role, although all these movements are aimed primarily at programmers, system administrators and advanced user profiles. Although not as friendly to the average user, it never hurts to have some ideas, and this is because, while GUIs are more convenient at first, they are slower than the command line for many tasks once you get the hang of it.

On previous occasions, we’ve mentioned the most useful commands for Windows and expanded on SDelete, a tool that allows you to delete files in a way that makes them difficult to recover. This time we’re going to expand it a bit robocopyinteresting tool mainly for copying directories and their contents.

What is Robocopy?

Accessible from the command line, both from PowerShell and from the command line, Robocopy is a robust reference for copying files, robust copy of the file in English. Basically it’s about a tool for copying and moving files from one place to another. In Windows 7, it was improved with the ability to work in multithreading (multithreading) to improve performance, somewhat reminiscent of what Google Chrome/Chromium meant against its rivals at the time.

Before we show some features with examples, the name of the tool will certainly remind many of RoboCop, the famous cyborg hero and protagonist of the universe of the same name, which takes place in a futuristic and dystopian Detroit. Is Robocopy a sarcastic reference to RoboCop? True or not, the reality is that there is, or at least once was, a GUI for Robocopy called RoboCop.

Using Robocopy

Using Robocopy to copy and move files

After explaining what Robocopy is, we’ll show how it works with a few examples. Revealing everything this tool can do in detail can go a long way, so we will focus on some of the most famous features to the folder to help the user get into using it.

We’ll start with the most basic use of the tool without introducing any parameters or arguments. To complete the feed without having to type everything, the user can autocomplete by pressing the Tab key. However, after specifying the source, there is a backslash before the end quote, so if there is a space in the directory or file name, it looks like this: '.\Xonotic OST (OGG)\'.

If the user doesn’t remove the last backslash, it escapes the trailing quotes, so instead of the end of the string (a file or folder name with one or more spaces), it tells the shell to take them literally, as if it were one more letter in the file or folder name. Because of this, you need to move the cursor to place it just before the second backslash and press the backspace key to start like this: '.\Xonotic OST (OGG)'. Another option is to leave only the quotes with the file or folder name between them: 'Xonotic OST (OGG)'.

In addition to specifying the origin, you also need to set the destination, which is the name of the folder that will be created in the copy process (Sintonic in this example). If you want to insert spaces, you have to enclose the destination name in quotes, which we didn’t use in our case, so the command is as follows:

robocopy '.\Xonotic OST (OGG)' Sintonic

If the Robocopy process did not throw any errors, the user should see where they are (C:\Users\Guillermo Puertas\Desktop'Guillermo Puertas is the username) a folder named Sintonic containing the source content (Xonotic OST (OGG)), which is a directory that contains the soundtrack for the video game Xonotic.

Robocopy supports multi-threaded copying, which is very useful for speeding up the copying or moving process in cases where there is one or several folders with a large amount of content. This function does not work by default, so you must provide a parameter /mt at the end activate it:

robocopy '.\Xonotic OST (OGG)' Sintonic2 /mt

Another interesting option is resettable modewhich can be activated with a parameter /z. With restartable mode, if a file copy is interrupted, Robocopy can pick up where it left off instead of copying the entire file again.

robocopy '.\Xonotic OST (OGG)' Sintonic3 /z

As is common with command interpreters, it is possible to use several parameters simultaneously. Here is an example with multi-threaded and restartable mode at the same time:

robocopy '.\Xonotic OST (OGG)' Sintonic4 /mt /z

parameter /mov allows you to move files content by origin, but not subdirectories and their contents, towards destination a without deleting the source directory:

robocopy .\Sintonic7\ Atomic1 /mov

parameter /move allows you to move files content by origin, but not subdirectories and their contents, towards destination a removing source if it does not contain subdirectories:

robocopy Atomic1 OMEGA /move

And now we will show you one of the most useful parameters of Robocopy, if not the most: /mir. view refers mirror in English, which means mirrorand what it does is mirror the entire tree or subtree of directories and files on the target.

robocopy '.\Xonotic OST (OGG)' Espejo /mir

If one searches recursive copy with all content is supplied by the parameter /s:

robocopy '.\Xonotic OST (OGG)' Sintonic5 /s

The following arguments we’ll mention require additional permissions to work, so it’s recommended to run PowerShell or a command prompt with administrator privileges, which you can do by right-clicking on the Start menu item and then clicking “Run.” as an administrator”. It is important to note that this will cause a terminal session C:\Windows\system32 instead of the user’s folder, which is C:\Users\nombreusuario.

Run PowerShell as an administrator on Windows

Here we mention three examples, starting with a backup mode (/b), which allows Robocopy to override file and folder permission settings (ACLs). This allows you to copy files that you would otherwise not be able to access.

robocopy '.\Xonotic OST (OGG)' Sintonic5 /b

parameter /zb starts the copy process in restartable mode. If access to the file is denied, the backup mode will start:

robocopy '.\Xonotic OST (OGG)' Sintonic6 /zb

As we said, these are just a few examples. All Robocopy parameters and options are exposed in the official Microsoft documentation.

Looking for alternatives to Robocopy to copy and move files in the same subdirectory

Robocopy is a tool primarily focused on mirroring or migrating files from one path to another, so using it for files that are located in the same directory becomes cumbersome and if successful. To make it easier to copy and move files in the same directory, we’ll use some alternatives to Robocopy.

For copy file can be used copy-item:

copy-item heavymetal.ogg copia-heavymetal.ogg

While for move Available move-item:

copy-item copia-heavymetal.ogg heavymetal-movido.ogg

Conclusion

Robocopy is an interesting tool for creating backup copies for users of the most important folders. We’ve stuck to the basic usage here, but the target doesn’t have to be in the same unit or team, so there’s more to it than meets the eye.

Cover image: Pixabay

Source: Muy Computer

Leave a Reply

Your email address will not be published. Required fields are marked *