Introduction: Using CLI Commands to Move Data Between Two Hard Drives

What are CLI commands?

First off, CLI stands for Command Line Interface. Commands are entered into this interface which then perform specific tasks. These tasks consist of doing certain operating system function from a CLI instead of the graphical Windows interface we use most of the time.

Why this is a beneficial skill to learn and when you would have to use this skill?

It is beneficial to learn because you will understand how to move around in the command line, find files, manipulate files, and other important commands. You are most likely to need to work in this way if you get an infection and have to disinfect your computer from the command line.

Step 1: How to Move Data Between Two Hard Drives

Moving data between two hard drives is quite simple when using DOS commands.

  • First, you must identify the two hard drives assigned letters. For instance, I have my C:\ drive which has my OS installed on it and I have a second hard drive assigned the letter D:\
  • Second, you will use the robocopy command to move the files you want to move. By default, robocopy does not copy empty directories as it just copies the files inside and not the entire directory. (for a better understanding of robocopy and the switches it offers see the list of all the recommended commands to know for moving files below)
  • Third, you will identify the data (could be a single folder or a whole directory) that you want to move. Get the filepath and that directory and remember it because it will be used in identifying what to copy.
  • Fourth, identify where you want to copied data to be moved to. (again, could be a folder or just the root of the directory)
  • Then you will type robocopy [filepath of what you want to copy [filepath of where you want the copied data to go]
  • And just like that, you will see the contents of the first file path emptied into the second specified file path

A side note: There are many ways to manipulate robocopy. Make sure you reference the switches to see how.

Step 2: How to Navigate Folders to Find Specific Files

Navigating directories to find files is also fairly simple and easy to reproduce once you know how.

  • First, navigate to the root directory by using the cd command followed by a backslash
    • cd\
  • There are multiple ways to search. You could search by name or file extension. Those are not the only two ways, but those are the ways being showcased.
    • Searching by name:
      • Lets say you knew there was a file named "folder" somewhere in your C: drive.
      • here you would use the dir command, the wildcard symbol and the /s switch for searching the current directory and all subdirectories.
      • The command would look like this
        • dir *[insert file name here]*.* /s dir *folder*.* /s
    • Searching by file extension:
      • If you do not know the name of the file, but know the program used to create it, this is good to know.
      • Again, you would use the dir command and use the * in place of the file name and type out the extension after it.
      • The command would look like this
        • dir *.[insert file extension here] /s dir *.exe /s
  • There is an example of the output produced as an image for this step.

Step 3: DIR (Directory)

Command: dir

  • Command usage: Displays a list of files and subdirectories in a directory.
  • Switches:
  • /A - Displays files with specified attributes.
  • /B - Uses bare format (no heading information or summary).
  • /C - Display the thousand separator in file sizes, which is the default setting. Use /-C to disable display of separator.
  • /D - Same as wide but files are list sorted by column.] /l - Uses lowercase.
  • /N - New long list format where file names are on the far right.
  • /O - List by files in sorted order.
  • /P - Pauses after each screenful of information.
  • /Q - Display the owner of the file.
  • /R -Display alternate data streams of the file.
  • /S - Displays files in specified directory and all subdirectories.
  • /T - Control what time field displayed or used for sorting
  • /W - Uses wide list format.
  • /X - Displays the short names generated for non-8dot3 file names. The format is that of /N with the short name inserted before the long name. If no short name is present, blanks are displayed in its place.
  • Examples:
    • dir
      • Lists all files and directories in the current directory. By default, the dir command lists the files and directories in alphabetic order.
    • dir *.exe
      • lists any file that ends with the .exe file extension
    • dir /ar
      • List only files in the current directory that have the read-only attribute.

Step 4: CD (Change Directory)

Command: CD [drive:][path] | CD [..]

  • Command usage: changes directories in MS-DOS and the Windows command line.
  • Switches: None
  • Examples:
    • Cd\
      • Goes to the highest level, the root of the drive.
    • Cd..
      • Goes back one directory
    • Cd\windows\system32
      • If present, would move into the system32 directory located in the Windows directory

Step 5: MD (Make Directory)

Command: MD [drive:]path

  • Command usage:
  • Allows you to create directories in MS-DOS.
  • Switches: None
  • Examples:
    • md testdir
      • Creates a directory named testdir in the working directory
    • md “space test”
      • Creates a directory named space test in the working directory
    • md c:\das\test
      • Creates a folder named das (if it does not exist) then creates a folder name test in das

Step 6: RD (Remove Directory)

Command: RD [/S] [/Q] [drive:]path

  • Command usage: Removes an empty directory in MS-DOS.
  • Switches:
  • /S - Removes all directories and files in the specified directory in addition to the directory itself. Used to remove a directory tree.
  • /Q - Quiet mode, do not ask if ok to remove a directory tree with /S.
  • Examples:
    • rd c:\full
      • If a directory contains files or folders when attempting to delete the directory you will receive "The directory is not empty." error message.
    • rd c:\test
      • Remove the test directory, if empty.
    • rd c:\test /s
      • permanently delete the test directory and all subdirectories and files.

Step 7: DEL (Delete File)

Command: DEL

  • Command usage: Deletes one or more files, not a folder
  • Switches:
  • /P - Prompts for confirmation before deleting each file.
  • /F - Force deleting of read-only files.
  • Examples:
    • del test.txt
      • Deletes the file that is named test and is also a .txt file in the working directory
    • del *.txt /p
      • Deletes any .txt file in the working directory and asks for confirmation before each deletion
    • del anotherTest.*
      • Deletes a file named anotherTest of any filetype

Step 8: ROBOCOPY (Robust Copy)

Command: ROBOCOPY source destination [file/files] [options]

  • Command usage: copies files and directories from one location to another.
  • Switches:
  • /s - copies subdirs but not empty ones
  • /e - copies subdirs including empty ones /mov - moves files (delete from source after copying)
  • Examples:
    • robocopy c:\oldTest c:\newTest *.txt
      • Copies all .txt files from the oldTest dir into newTest
    • Robocopy c:\oldTest c:\newTest
      • Copies all files from oldTest into newTest
    • Robocopy c:\oldTest c:\newTest /e
      • Copies all files and dirs (including empty ones) from oldTest into newTest