How to copy files using the command line

Author: William Ramirez
Date Of Creation: 24 September 2021
Update Date: 1 July 2024
Anonim
Windows Command Line Tutorial - 9 - Copying and Moving Files
Video: Windows Command Line Tutorial - 9 - Copying and Moving Files

Content

In this article, you will learn how to copy individual files and files from a folder in Windows using the command line.

Steps

Part 1 of 3: How to Prepare to Copy

  1. 1 Determine where the file is located. You need to find out in which directory the file is stored in order to specify it on the command line.
    • To find the directory, in Explorer, navigate to the folder with the file, and then click on the address bar at the top of the Explorer window.
    • Most of the files are located in the following directory: [drive letter]: Users [username] (for example, "C: Users John"). This directory contains almost all files created by the user.
    • For example, the file on the desktop is in the following directory: C: Users Ivan Desktop, and the file is in the Documents folder in the C: Users Ivan Documents directory.
  2. 2 Make a note of the file name. This is required to copy the file. Be aware that the command line is case sensitive, so make sure to write down the file name correctly.
  3. 3 Open the start menu . Click on the Windows logo in the lower left corner of the screen.
  4. 4 Enter command line. This will search for the Command Line utility.
  5. 5 Click Command Prompt . You will find this icon at the top of the Start menu. A command prompt window will open.
    • Be aware that on a public computer (like a school), you won't be able to open a command prompt.

Part 2 of 3: How to copy a single file

  1. 1 Enter the command to change to a different directory. Enter cdand then press Space; key ↵ Enter do not press.
  2. 2 Enter the directory where the file you want is located.
  3. 3 Click on ↵ Enter. On the command line, you will change to the specified directory.
  4. 4 Enter the command to copy the file. Enter copyand then press Space; key ↵ Enter do not press.
  5. 5 Enter a name for the file. Enter a file name and then press Space. Enter the file name with the file extension (for example, .txt in the case of a text file). Key ↵ Enter do not press.
    • If there are spaces in the file name, enclose them in quotation marks. For example, the file name "Pickles are Good.txt" on the command line should be entered like this: Pickles "" are "" Good.txt.
  6. 6 Enter the destination directory. Enter a directory (for example, C: Users [your username] Desktopto which the file will be copied.
    • If you do not enter a destination directory, the file will be copied to your personal directory (for example, "C: Users [your username]").
  7. 7 Click on ↵ Enter. The file will be copied to the specified directory. To open the copied file, navigate to the appropriate directory in the Explorer window.

Part 3 of 3: How to copy files from a folder

  1. 1 Change to the directory with the folder. Enter cd, press Space, enter the directory with the folder and press ↵ Enter.
    • For example, to copy files from the Example folder on your desktop, enter the directory C: Users Ivan Desktop.
  2. 2 Enter the command robocopy. Enter robocopyand then press Space; key ↵ Enter do not press.
  3. 3 Enter the folder name. Enter the name of the folder you want to copy files from, and then press Space. Key ↵ Enter do not press.
    • If there are spaces in the folder name, enclose them in quotation marks.
  4. 4 Enter the destination directory. Enter the directory where you want to copy the files from the folder.
    • If there are many files in the source and destination folders, they will get mixed up because the source folder itself will not be copied.
  5. 5 Click on ↵ Enter. The file from the source folder will be copied to the destination folder.

Tips

  • To copy all the files that are in the directory, enter the command copy * [file type] (For example, copy *. txt).
  • To create a destination folder and copy multiple files into it at once, enter the destination folder directory (including the destination folder itself) in conjunction with the "robocopy" command.
  • If you copy files that are on your desktop to a new folder, it will be renamed Desktop.

Warnings

  • Copying files and folders via the command line is quite risky if you don't know what you are doing. Do not touch folders and files whose purpose you do not know.