Robocopy Command Syntax and Examples

Posted on

Robocopy Command is usually used on Windows to copy files and directories from a location to another. Aside from that, this one also prints a detailed report of the copy operation. In this page, you can find the Robocopy Command syntax and examples.

Robocopy source destination [file [file]…] [option]

Source: Source directory (drive:\path or \\server\share\path).

Destination: Destination directory (drive:\path or \\server\share\path).

File: File(s) to copy (names/wildcards: default is “*.*”).

Copy options:

  1. /S: It copies subdirectories, but not the empty ones.
  2. /E: It copies subdirectories, including the empty ones.
  3. /LEV:n: It only copies the top n levels of the source directory tree.
  4. /Z: It copies files n the restartable mode.
  5. /B: It copies files in backup mode.
  6. /ZB: It uses restartable mode. If the access is denied, use backup mode.
  7. /EFSRAW: It copies all encrypted files in EFS RAW mode.
  8. /COPY:copyflag[s]: What to COPY for files (default is /COPY:DAT).

(copyflags: D means Data, A means Attributes, T means Timestamps).

(S means Security means NTFS ACLs, O means Owner info, U means aUditing info).

  1. /DCOPY:T: It copies the directory timestamps.
  2. /SEC: It copes files with security (equivalent to /COPY:DATS).
  3. /COPYALL: It copies all file info (equivalent to /COPY:DATSOU).
  4. /NOCOPY: It copies no file info (useful with /PURGE).
  5. /SECFIX: It fixes the file security on all files, including the skipped ones.
  6. /TIMFIX: It fixes files on all files, including the skipped ones.
  7. /PURGE: It deletes the dest files or dirs that no longer exist in the source.
  8. /MIR: It minors a directory tree (equivalent to /E plus /PUDGE).
  9. /MOV: It moves files (delete form the source after copying).
  10. /MOVE: It moves files and dirs. (delete from the source after copying).
  11. /A+:[RASHCNET]: It adds the given attributes to the copied files.
  12. /A-:[RASHCNET]: It removes the given attributes from the copied files.
  13. /CREATE: It creates the directory tree and zero-length files only.
  14. /FAT: It creates destination files using 8.3 FAT file names only.
  15. /256: Turn off very long path (> 256 characters) support.
  16. /MOT:n: It monitors sources; run again when more than n changes are seen.
  17. /MOT:m: Monitor source; run again in m minutes time, if changed.
  18. /RH:hhmm-hhmm: It runs hours – times when the new copies may be started.
  19. /PF: It checks run hours on a per file (not per pass) basis.
  20. /IPG:n: Inter=packet gap (ms), to the free bandwidth on slow lines.
  21. /SL: It copies symbolic links versus the target.
  22. /MT[:n]: DO some threaded copies with n threads (default 8). N has to be at least 1 and not greater compared to 128. This one is incompatible with the /IPG and /EFSRAW options. Redirect the output using /LOG option or the better performance.

File Selection Options:

  1. /A: It copies only the files with the archive attribute package.
  2. /M: It copies only the files with the archive attribute and reset it.
  3. /IA:[RASHCNETO]: It includes only the files with any of the given attributes package.
  4. /XA:[RASHCNETO]: It excludes files with any of the given attributes package.
  5. /XF file [file]…: It excludes files matching given names or paths or wildcards.
  6. /XD dirs. [dirs.]…: It excludes directories matching given names or paths.
  7. /XC: It excludes changed files.
  8. /XN: It excludes newer files.
  9. /XO: It excludes older files.
  10. /XX: It excludes extra files and directories.
  11. /XL: It excludes lonely files and directories.
  12. /IS: It includes the same files.
  13. /IT: It includes tweaked files.
  14. Etc.

Retry Options:

  1. /R:n: It is the numbers of retries on failed copies: default 1 million.
  2. /W:n: It is the wait time between retries: default is 30 seconds.
  3. /REG: It saves /R:n and /W:n in the registry as default settings.
  4. /TBD: It waits for sharenames to be defined (retry error 67).

Logging Options:

  1. /L: It lists only, does not copy, timestamp or delete any files.
  2. /X: It reports all extra files, not only the chosen ones.
  3. /V: It produces verbose output, displaying skilled files.
  4. /TS: It includes source file timestamps in the output.
  5. /FP: It includes the full pathname of files in the output.
  6. /BYTES: It prints sizes as bytes.
  7. /ETA: It shows estimated time of arrival of copied files.
  8. /LOG:file: It is the output status to LOG file (overwrite existing log).
  9. /LOG+:file: It is the output status to LOG file (append existing log).
  10. /UNILOG:file: It is the output status to LOG file as UNICODE (overwrite existing log).
  11. Etc.

Job Options:

  1. /JOB:jobname: It takes parameters from the named job file.
  2. /SAVE:jobname: It saves parameters to the named job file.
  3. /QUIT: It quits after processing the command line to view parameters.
  4. /IF: It includes the following files.
  5. Etc.

Robocopy examples:

The first example is robocopy c:\hope c:\hope2 *.txt. In this example, any .txt file will be copied from the hope directory into the hipe2 directory. Every time you want to copy one or more files and not a full directory the file has to be specified after the destination directory.

The second example is robocopy c:\hope c:\hope2. In this one, the robocopy command will copy all files (not directories) in the hope directory to the hope2 directory.

The third one is robocopy c:\hope c:\hope2 /e. In this one, all files and folders, including the empty ones, are copied from the hope directory to the hope2 directory.

The fourth one is robocopy c:\hope c:\hope2 /MIR. This one mirrors what is in c:\hope into c:\hope2 and cleans up any files in the hope2 directory that do not exist in the hope directory. You can use the /mir which switches deliberately since it deletes files that do not match in the destination directory.

The fifth one is robocopy \\computer\hope C:\hope2. This one will copy any of the files in the hope directory on the network computer named computer to the current computer hope2 directory.

Leave a Reply

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