Command Line - Taking command for the power tester

It seems funny, but sometimes the most powerful trick in your bag can be some of your oldest knowledge. If you ever want to show your true power and put a newbie in their place just type in CMD and start dancing through shell commands. These little nuggets always work and are not reliant on the interface to perform their duties. Done correctly they can provide information that is three or four layers deep in Windows.

This is not a comprehensive listing of useful commands, there are many resources on line as well as the PowerShell/Cygwin additions (but you cant always count on those being available). Check out Microsoft's help site or Google command line/DOS commands for more information and opportunities to use the command line as a part of your testing.

Some of the commands below are used by themselves, others in batch files (there is a blast from the past as well). All are things I have used to facilitate some part of a test plan/

FTP - use this to move files between machines, it usually takes a batch file, but is so much easier than learning the objects in an FTP client. A great reference to using FTP in dos is located at http://www.dostips.com/DtTipsFtpBatchScript.php . The syntax can be complex so use the reference for ideas and modify to your needs. For the purposes of this post, and for accuracy, I have retrieved the exact syntax from Wikipedia at http://en.wikipedia.org/wiki/List_of_DOS_commands

If you are using these commands within an automation script, please be sure to suppress prompting, it will prevent you from ripping hair out.

MOVE - this command will allow you to easily move a file(s)

MOVE [/Y | /-Y] [drive:][path]filename1[,...] destination
To rename a directory:
MOVE [drive:][path]dirname1 dirname2
 
  /Y        Suppresses prompting to confirm overwriting of the destination.
  /-Y       Causes prompting to confirm overwriting of the destination.
            The switch /Y may be present in the COPYCMD environment variable.
            This may be overridden with /-Y on the command line.
 
  [drive:][path]filename1 Specifies the location and name of the file
                          or files you want to move.
  destination             Specifies the new location of the file. Destination
                          can consist of a drive letter and colon, a directory
                          name, or a combination. If you are moving only one
                          file, you can also include a filename if you want
                          to rename the file when you move it.
  [drive:][path]dirname1  Specifies the directory you want to rename.
  dirname2                Specifies the new name of the directory.

MKDIR - allows you to create a directory

MKDIR [drive:]path
MD [drive:]path

COMP - Compare files

COMP [data1] [data2] [/D] [/A] [/L] [/N=number] [/C]

   data1     Specifies location and name(s) of first file(s) to compare.
  data2     Specifies location and name(s) of second files to compare.
  /D        Displays differences in decimal format. This is the default
            setting.
  /A        Displays differences in ASCII characters.
  /L        Displays line numbers for differences.
  /N=number Compares only the first specified number of lines in each file.
  /C        Disregards case of ASCII letters when comparing files.
 To compare sets of files, use wildcards in data1 and data2 parameters.

COPY - Copy Files

COPY [/A | /B] source [/A | /B] [+ source [/A | /B] [+ ...]] [destination

  [/A | /B]] [/V] [/Y | /-Y]
   source       Specifies the file or files to be copied. The source can
               also be a device (e.g., CON for console).
  /A           Indicates an ASCII text file.
  /B           Indicates a binary file.
  destination  Specifies the directory and/or file name for the new file(s).
  /V           Verifies that new files are written correctly.
  /Y           Suppresses prompting to confirm you want to overwrite an
               existing destination file.
  /-Y          Causes prompting to confirm you want to overwrite an
               existing destination file.
The switch /Y may be preset in the COPYCMD environment variable.
To append files, specify a single file for destination, but multiple files
for source (using wildcards or file1+file2+file3 format).

DEL - Delete file(s)

DEL [drive:][path]filename [/P]

 
  [drive:][path]filename  Specifies the file(s) to delete.  Specify multiple
                          files by using wildcards.
  /P                      Prompts for confirmation before deleting each file.
  /Q                      Quiet mode, do not ask if ok to delete on global wildcard

DELTREE - Delete Directories

To Delete one or more directories:

DELTREE [/Y] [drive:]path [[drive:]path[...]]
 
  /Y              Suppresses prompting to confirm whether you want to
                  delete the subdirectory.
  [drive:]path    Specifies the name of the directory you want to delete.
 
Note: Use DELTREE with caution. Every file and subdirectory within the
specified directory will be deleted.

ECHO - Displays messages On or Off

ECHO [ON | OFF]

  ECHO [message]
 Type ECHO without parameters to display the current echo setting.

FC - whole file comparison with verbose output

FC [/A] [/C] [/L] [/LBn] [/N] [/T] [/W] [/nnnn] [drive1:][path1]filename1

  [drive2:][path2]filename2
FC /B [drive1:][path1]filename1 [drive2:][path2]filename2
 
  /A     Displays only first and last lines for each set of differences.
  /B     Performs a binary comparison.
  /C     Disregards the case of letters.
  /L     Compares files as ASCII text.
  /LBn   Sets the maximum consecutive mismatches to the specified number of
         lines.
  /N     Displays the line numbers on an ASCII comparison.
  /T     Does not expand tabs to spaces.
  /W     Compresses white space (tabs and spaces) for comparison.
  /nnnn  Specifies the number of consecutive lines that must match after a
         mismatch.

FIND - Searches for text strings within one or more files as specified

FIND [/V] [/C] [/N] [/I] [/S] "string" [[drive:][path]filename[ ...]]

 
  /V        Displays all lines NOT containing the specified string.
  /C        Displays only the count of lines containing the string.
  /N        Displays line numbers with the displayed lines.
  /I        Ignores the case of characters when searching for the string.
  /S        Search subdirectories also.
  "string"  Specifies the text string to find.
  [drive:][path]filename
            Specifies a file or files to search.
 
If a pathname is not specified, FIND searches the text typed at the prompt
or piped from another command.

PRINT - allows you to create output from dos commands

PRINT [/D:device] [/B:size] [/U:ticks1] [/M:ticks2] [/S:ticks3]

      [/Q:qsize] [/T] [[drive:][path]filename[ ...]] [/C] [/P]
 
  /D:device   Specifies a print device.
  /B:size     Sets the internal buffer size, in bytes.
  /U:ticks1   Waits the specified maximum number of clock ticks for the printer
              to be available.
  /M:ticks2   Specifies the maximum number of clock ticks it takes to print a
              character.
  /S:ticks3   Allocates the scheduler the specified number of clock ticks for
              background printing.
  /Q:qsize    Specifies the maximum number of files allowed in the print queue.
  /T          Removes all files from the print queue.
  /C          Cancels printing of the preceding filename and subsequent
              filenames.
  /P          Adds the preceding filename and subsequent filenames to the print
              queue.
 Type PRINT without parameters to display the contents of the print queue.

XCOPY - power copying tool

XCOPY [/Y|/-Y] source [destination] [/A|/M] [/D:date] [/P] [/S] [/E] [/V] [/W]
  source       Specifies the file(s) to copy.
  destination  Specifies the location and/or name of new files.
  /A           Copies files with the archive attribute set,
               doesn't change the attribute.
  /M           Copies files with the archive attribute set,
               turns off the archive attribute.
  /C           Ignores errors.
  /D:date      Copies files changed on or after the specified date.
  /P           Prompts you before creating each destination file.
  /S           Copies directories and subdirectories except empty ones.
  /E           Copies any subdirectories, even if empty.
  /V           Verifies each new file.
  /W           Prompts you to press a key before copying.
  /Y           Suppresses prompting to confirm you want to overwrite an
               existing destination file.
  /-Y          Causes prompting to confirm you want to overwrite an
               existing destination file.
 The switch /Y may be preset in the COPYCMD environment variable.
This may be overridden with /-Y on the command line

This is not a comprehensive list of commands to use. If you learn these and have a good grasp on DOS, take a look at PowerShell or CygWin, both also have a great deal of information available. Applying these tools can assist you in making automation and testing incredibly powerful. Remember to use the tools you have.

command-line testing tips utilities

About Inflectra

Our mission to helping our customers - large corporations, small businesses, professional services firms, government agencies and individual developers – with the means to effectively and affordably manage their software development and testing lifecycles, so as to decrease the time to market and increase return on investment.

At Inflectra, we are fully committed to provide our customers with the very best products and customer service. We believe in going the extra mile to ensure that each customer is satisfied with our software products. We have the experience and the commitment to deliver the products customers need to deliver their projects and assure quality every step of the way. (Learn More)

Our Guarantee

We are so confident that you will be fully satisfied with our products that we offer a 30-day, unconditional, money back guarantee! (Learn More)