5.3. Copying and Moving Files

Doesn't it seem like when you finally get things organized, it's time to start all over again? When organizing and backing up files, you will often be required to copy or move files to new locations, either in another directory or on another disk. The following sections provide an overview of the commands that help you with these tasks.

NOTE

All the command line tools in this section have not changed substantially since MS-DOS.

5.3.1. copy

The copy command expects you to give at least the name of the file you would like to copy. If you provide only one filename, the selected file is copied into the current directory. If you provide a source filename and a destination directory by using a command like

copy c:\source\myfile.txt c:\destination

the file will be copied into the destination directory. You can also rename files while you are copying them by using a command like this:

copy c:\source\*.bat c:\destination\*.old

The preceding command would copy all files with an extension of .bat from the source directory and rename them with an .old extension in the destination directory.

If you are about to overwrite an existing file, you will be prompted to confirm the operation. This can be suppressed if you use /Y at the end of your copy command. /Y answers "yes" to the copy command's "confirm overwrite?" question. If you want to consistently overwrite destination files, you can set the copycmd environment variable to /Y in the same manner that you set ...

Get CompTIA A+® Certification All-In-One For Dummies®, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.