While Windows is seen by the vast majority of the public as an operating system that is used through the graphical interface, that does not mean that it does not have pre-installed or at its disposal interesting tools that work through the command line, that interface whose use is usually associated with Linux.
What’s more, even the Microsoft, without making much noise, has been taking care of the use of the command line in Windows and even seems to have given it more prominence in recent times, something that from certain points of view can be understood as a kind of surrender to the obvious advantages it brings compared to graphical interfaces, although the latter are also better in certain aspects.
Microsoft has been developing and promoting for many years PowerShell. This command line interpreter was for a very long time associated with Windows, but the company decided in 2016 to make it open source (although reserving some cards) and bring it to Linux and macOS, so since then it competes with other solutions in the same field such as Bash and Zsh. Compared to the command prompt, one of its advantages is that it allows you to create your own commands and scripts using the C# programming language.
The care that the Redmond giant devotes to the command line was most recently evident with. Windows TerminalIt is capable of handling both the command prompt (what some colloquially call the MS-DOS emulator) and PowerShell and can also run separate tabs for WSL, the Windows subsystem for Linux that allows running a full Linux operating system on top of Microsoft’s Linux.
As we can see, the command line is far from being a corpse in Windows and what’s more, it is seen that Microsoft has been giving it a greater prominence in recent times, although all these moves are mainly aimed at programmers, system administrators and advanced user profiles. Although it is not so friendly for the common user, it never hurts to have certain notions, and although graphical interfaces are initially more comfortable, for many tasks they are slower than the command line once the latter is mastered.
On previous occasions we mentioned the most useful commands for Windows and we extended with SDelete, a tool that allows you to delete files so that it is difficult to recover them. This time we will expand a little with Robocopyan interesting tool for copying mainly directories and their contents.
What is Robocopy
Robocopy is accessible from the command line, either from PowerShell or the command prompt, and is a robust file copying reference, robust file copy in English. Basically it is a tool for copying and moving files from one place to another.. In Windows 7 it was enhanced with the possibility to run in multithreading (multithreading) to improve performance, which is somewhat reminiscent of what Google Chrome/Chromium did at the time against its rivals.
Before showing with examples some of the features, surely the name of the tool reminds many of RoboCop, the well-known cyborg hero and protagonist of the universe of the same name that takes place in a futuristic and dystopian Detroit. Is Robocopy a sarcastic reference to RoboCop? Whether or not it is true, the reality is that there is, or at least came to be, a graphical interface for Robocopy called RoboCop.
Using Robocopy to copy and move files.
After explaining what Robocopy is, we are going to show how it works with some examples. To expose all that this tool can do in a detailed way could take a lot of time, so we will focus on some of the most popular features About a folder to help the user get acquainted with its use.
We start with the most basic use of the tool, without entering any parameters or arguments. To complete the origin without having to type everything, the user can autocomplete by pressing the tab key. However, after entering the source, there is a backslash in front of the closing quotation marks, so it looks like this if there is a space in the directory or file name:
'.\Xonotic OST (OGG)\'.
If the user does not remove the last backslash, he will be escaping the closing quotation marks, so instead of the end of the character string (the file or folder name with one or more spaces) he is telling the command interpreter to understand them literally, that is, as if it were one more letter of the file or folder name. Because of this, you must move the cursor to place it just in front of the second backslash and press the backspace key to make the source look like this:
'.\Xonotic OST (OGG)'. Another possibility is to leave only the quotation marks with the file or folder name between them:
'Xonotic OST (OGG)'.
In addition to setting an origin, you must also set a destination.which is the name of the folder that will be created in the copying process (Sintonic in this example). If you want to put spaces you have to put the name of the destination inside quotation marks, which we have not used in our case, so the command is as follows:
robocopy '.\Xonotic OST (OGG)' Sintonic
If the Robocopy process has not thrown any error, the user should be able to see in the location where it is located (
C:\Users\Guillermo Puertas\Desktop', Guillermo Puertas is the user’s name) a folder called Sintonic with the contents of the source (
Xonotic OST (OGG)), which is a directory containing the soundtrack of the video game Xonotic.
Robocopy supports multithreaded copyingwhich comes in handy to speed up the copying or moving process in cases where there are one or several folders with a large amount of contents. The feature does not work by default, so you have to set the parameter
/mt at the end to activate it:
robocopy '.\Xonotic OST (OGG)' Sintonic2 /mt
Another interesting possibility is the resettable modewhich can be activated with the parameter
/z. With the resettable mode, if a file copy is interrupted, Robocopy can resume copying from where it left off instead of copying the whole file again.
robocopy '.\Xonotic OST (OGG)' Sintonic3 /z
As is normal for command interpreters, it is possible to use several parameters at the same time. Here is an example with multiprocessing and resettable mode at the same time:
robocopy '.\Xonotic OST (OGG)' Sintonic4 /mt /z
/mov allows you to move the files contained by the source, but not the subdirectories and their contents, to the destination, and without deleting the source directory:
robocopy .\Sintonic7\ Atomic1 /mov
/move allows you to move the files contained by the source, but not the subdirectories and their contents, to the destination, and deleting the source if it does not contain subdirectories.:
robocopy Atomic1 OMEGA /move
And now we expose one of the most useful parameters of Robocopy, if not the most:
/mir. Mir refers to mirror in English, which means mirrorand what it does is to mirror the whole tree or subtree of directories and files in the destination.
robocopy '.\Xonotic OST (OGG)' Espejo /mir
If one looks for the recursive copy with all the contents, this is supplied by the parameter
robocopy '.\Xonotic OST (OGG)' Sintonic5 /s
The following arguments we are going to mention require additional privileges to work, so it is advisable to start PowerShell or the command prompt with administrator privileges, which you do by right-clicking on the entry in the Start menu and then clicking on “Run as administrator”. It is important to note that this will make the terminal session in
C:\Windows\system32 instead of the user’s folder, which is
Here we are going to mention three examples, starting with a. backup mode (
/b) that allows Robocopy to override file and folder permission (ACL) settings. This allows copying of files to which it would otherwise not have access.
robocopy '.\Xonotic OST (OGG)' Sintonic5 /b
/zb starts the copying process in resettable mode. In case access to the file is denied, the backup mode is started:
robocopy '.\Xonotic OST (OGG)' Sintonic6 /zb
As we have already said, these are just a few examples. All the parameters and possibilities of Robocopy are described in the official Microsoft documentation.
Looking for alternatives to Robocopy to copy and move files within the same subdirectory.
Robocopy is a tool mainly focused on mirroring or migrating files from one path to another, so using it for files within the same directory becomes cumbersome, and that’s if you can do it. To facilitate copying and moving files within the same directory, we will use a couple of alternatives to Robocopy.
For copy a file it is possible to use
copy-item heavymetal.ogg copia-heavymetal.ogg
Whereas for move is available
copy-item copia-heavymetal.ogg heavymetal-movido.ogg
Robocopy is an interesting tool for backing up the folders most important to the user. Here we have stuck to a basic use, but the destination does not have to be located on the same drive or on the same computer, so it can treasure more than it appears.
Cover image: Pixabay