Windows Command Line (C) Copyright 2017 by Peter Chapin ================================== In this document I summarize a few of the basic commands you can type into the Windows command prompt. These commands are often quicker and easier to use (once you know them) than their equivalent graphical operations. Understanding the Prompt ------------------------ The command prompt shows you the "current working directory". If you specify the name of a file without specifying the name of a drive or directory (I will use "directory" and "folder" interchangeably), the system assumes that file is in the current working directory. For example: M:\SUBDIR>_ In this case the current working directory is named "SUBDIR". It is located just off the root of the M: drive. I can specify files in this directory by just using their names without any other path information. Command lines consist of a command followed by one or more words separated by spaces. These additional words are called the "arguments" of the command. For example: M:\SUBDIR> copy afile.txt bfile.txt Here the command is "copy." It is being provided with two arguments, "afile.txt" and "bfile.txt." The copy command treats the two arguments as file names. It copies the contents of the first file to the second file. Both of these files are taken relative to the current working directory (M:\SUBDIR). Here is another example: M:\SUBDIR> copy S:\CIS\netapps\readme.txt readme.txt In this case the first argument is the full (absolute) name of a file on the S: drive and located in the netapps folder inside the CIS folder. The destination file is just readme.txt in the current working directory (M:\SUBDIR). The Commands ------------ M:\> dir The "directory" command shows you a list of the files in the current working directory or in the directory you name as an argument. For example, a command such as "dir S:\CIS" shows you the files in the CIS folder on the S: drive. M:\> copy source.txt destination.txt The "copy" command copies the file named as its first argument to the file named as its second argument. If the destination file does not exist, it is created. After the copy the two files are independent and identical. As another example "copy source.txt c:\source.txt" copies source.txt from the current working directory to source.txt in the root directory of the C: drive. M:\> ren oldname.txt newname.txt The "rename" command changes the name on an existing file. If a file already exists with the new name, the command fails with an error message. No copy of the file is made. M:\> del afile.txt The "delete" command erases the named file. Normally the file can't be recovered (it is not put into the recycle bin). M:\> md subdir The "make directory" command creates a subdirectory (or subfolder) with the name specified as its argument. M:\> cd subdir M:\SUBDIR>_ The "change directory" command changes the current working directory to be that of the named directory. After a cd command, the prompt should change to reflect the new current working directory (as shown above). You can use the command "cd .." to change to the directory just "above" your current directory. For example: M:\SUBDIR> cd .. M:\>_ M:\> rd subdir The "remove directory" command deletes a subdirectory (or subfolder). The directory must be empty of files before this command will work. Wildcard Characters ------------------- You can use certain special letters in your commands to refer to entire groups of files easily. The most common such "wildcard" character is the '*'. It might be used in the following way M:\> del *.txt Here the delete command is being told to delete all files with names that end with ".txt". The '*' before the .txt implies that the first part of the name can be anything. Thus '*' is shorthand for "anything". M:\> del *.* This command deletes all files since both the name and the extension can be anything. Use this command carefully! You might end up deleting more than you want. Some of the commands, such as copy, can accept the name of a directory as the destination. For example M:\> copy *.c myprogs If "myprogs" is the name of a directory (you did a "md myprogs" some time before) then this command copies all files ending with .c into the myprogs directory. This could be quite a few files. You could then delete them all from the current working directory with "del *.c". A more complete example of this is M:\> md myprogs M:\> copy *.c myprogs M:\> del *.c M:\> cd myprogs M:\myprogs>_ Here I've just created a subfolder of M:\, moved all my .c files into it, and then changed to that subfolder so that I can continue my work. Note that in this case, the copy and del commands can be combined into a single "move" command. M:\> md myprogs M:\> move *.c myprogs M:\> cd myprogs M:\myprogs>_