Sub topic 3
Copying Data and Checking Network Configuration
This chapter assumes you can open an elevated Command Prompt, move between folders with cd, and recognize an IP address, DNS server, and default gateway. It covers three copy tools, then three basic network commands.
Copying data: copy, xcopy, and robocopy
Windows has three command-line copy tools. Pick the one that matches the job.
| Tool | Best for | Notable limits |
|---|---|---|
| `copy` | One file or a few files | Does not copy folders or subfolders |
| `xcopy` | Folder trees, with `/s` or `/e` | Older tool, fewer retry options |
| `robocopy` | Large or repeated jobs, backups, network copies | Needs the right switches, and its exit codes differ from most commands |
copy is the simplest. copy report.docx D:\Backup places one file in the destination folder. xcopy adds subfolders. xcopy C:\Data D:\Backup /e /i copies the whole tree, including empty folders. /i tells xcopy the destination is a folder.
robocopy (Robust File Copy) is the tool Microsoft recommends for serious copying. It retries failed files, resumes interrupted copies, and prints a summary.
robocopy C:\Data D:\Backup /E /R:2 /W:5/Ecopies all subfolders, including empty ones./R:2retries a failed file twice. The default is one million retries, so set this./W:5waits 5 seconds between retries.
Add /MIR to mirror a source to a destination. A mirror also deletes files in the destination that are missing from the source, so check the destination path before you run it.
Network configuration: ipconfig, hostname, and ping
Start network troubleshooting by checking the machine's own settings.
ipconfig /all
ipconfig /release
ipconfig /renew
ipconfig /flushdnsipconfigalone shows the IP address, subnet mask, and default gateway for each adapter.ipconfig /alladds the MAC address, DHCP server, lease times, and DNS servers./releaseand/renewdrop the current DHCP lease and request a new one./flushdnsclears the local DNS resolver cache. Use it when a name resolves to an old address.
An address that starts with 169.254 is an APIPA address. The computer assigned it to itself because no DHCP server answered. Check the cable, Wi-Fi, or DHCP service, then run ipconfig /renew.
hostname prints the computer's name and nothing else. It is a quick way to confirm which machine you are working on.
ping sends test packets and reports whether a reply came back. Work outward in this order:
ping -n 4 127.0.0.1
ping -n 4 example.com- Ping
127.0.0.1(the loopback address). A reply shows the local TCP/IP stack works. - Ping the default gateway from
ipconfig. A reply shows the local network works. - Ping a remote IP address such as
8.8.8.8. A reply shows Internet routing works. - Ping a name such as
example.com. A reply shows DNS works.
-n 4 sends four packets. On Windows, ping runs forever only with -t, and you stop it with Ctrl+C.
If the remote IP replies but the name fails, the problem is DNS, not connectivity.
Exercise
A user can ping 8.8.8.8 successfully but cannot ping example.com. Which command clears the local name cache, and what is the likely cause?
Show answer
Run ipconfig /flushdns. The likely cause is a DNS problem, such as a wrong DNS server or a stale cache, because IP connectivity works.
Exercise
You need to copy C:\Data and all its subfolders, including empty ones, to D:\Backup, retrying a failed file twice with 5 seconds between tries. Which command does this?
Show answer
robocopy C:\Data D:\Backup /E /R:2 /W:5