MS-DOS (cmd.exe) command prompt: CD, MD, copy

This article is from our Febooti archive, it was relevant then, and I think that it is still relevant today (a few details changed).

Another very common command is cd – Change Directory (also works in Linux). This changes the directory you are currently in.

C:\>cd \users\default

CD command in Windows 8.1
CD command in Windows 8.1

This example might not work for you if you do not have drive C, and in the drive C there are no users\default folder, however the scheme is still the same. You have to type CD followed by the root, the first \, followed by the first directory under the root, users, followed by the next directory, default. You would keep doing this until you got to your last directory.

Another useful command is being able to create directories. Directories are given names just like files are. They can contain numbers and letters but be careful of some of the special characters like * ? / ” ‘, etc. Avoid these. Also, when you make a directory try to avoid adding an extension. Directories with extension is a little bit confusing but fully valid. To make a directory, use the MD command (Make Directory). Use the following syntax:

C:\users\default>md MyDirectory

MD command in Windows 8.1
MD command in Windows 8.1

Have you ever copied and pasted a file from one folder to another? Maybe you just copied and pasted a snippet of text or a picture to another file. Suppose you wanted to copy a file and make a duplicate of that file with a different name. In the next example, we have 1 file called SourceDocument1.doc. The contents of 2nd file will be the same as we are creating a Document2.doc using our existing SourceDocument1.doc file.

C:\>copy SourceDocument1.doc Document2.doc

All that you have to do for the copy command to work is place the original file’s name first. Press the space bar. Then put what you wish to name the new, copied, document. This is a good simple way to make a backup file. There are typically two messages that will come back – ‘1 file(s) copied’ or ‘File not found’. You can always use the DIR command to make sure you have the correct filename (see previous article with DIR command examples). You can experiment with using different drive letters and directories using the same principles we used to create and change directories. To copy a group of files you can use what is called the wildcard. Here is an example:

C:\>copy *.doc D:\

In this example the *.doc matches all the files ending in .doc in current directory, and files are copied to the drive D (flash drive in my case). Be careful with the wildcard when deleting files as it is very easy to delete more than what you want to delete.

You can press the CTRL+C (Control key and the C key), looks like ^C on most documentation, to stop the copy progress or batch file from executing. In case of batch files, you will then be asked if you wish to terminate the batch file. Press a Y for yes or a N (stands for no) to continue on processing the batch script or let the current process to finish. You can also use the CTRL+Break key combination. This combination produces the same output as the CTRL+C combination (except for the Ping command). Exceptions to rules are common, but you will learn then as we go with more details.

Something that you might find interesting later on when you learn about the ECHO command is that when you enter ECHO OFF at the command prompt you will in essence “lose” your prompt. You need to type ECHO ON in order to get back to where you were. Not very useful in command prompt, but very useful when you are writing a batch file (.bat).

Next article tomorrow: What is a batch script?
Previous article: MS-DOS (cmd.exe) prompt basic commands

This article is from our Febooti archive, it was relevant then, and I think that it is still relevant today (a few details changed).

Edit Sep 26, 2014: added link to the next article.

MS-DOS (cmd.exe) prompt basic commands

This article is from our Febooti archive, it was relevant then, and I think that it is still relevant today (a few details changed).

Since most of users do not use command prompt as their primary interaction with the operating system then we will go over the pure basics. These commands can also be used in a batch files. Because a batch file is a way of executing frequently entered DOS commands quicker, it would be a good idea to go over some command line basics.

In the previous article there is instruction how to access the command prompt – simply click the Start button (or Windows key on the keyboard) in the lower left hand corner of the screen followed by clicking on the Run… option (or simply typing cmd.exe on newer Windows). When you do this, a small box will appear in the lower left hand corner of the screen. To access the command prompt simply type cmd or command.

cmd.exe
cmd.exe

Now that we have a command prompt up, we will open a program. Let’s start with the Windows calculator. In the black screen you should see something to the extent of C:\>. You might have more to it or you might simply have C:\>. Either way to access the Windows Calculator you simply type calc at this screen. Then hit the enter key on your keyboard. The Windows calculator will pop-up immediately. This is how you are able to open any program from the DOS prompt (technically any program, program’s working folder must be in the path environment variable).

C:\>calc

Windows Calculator
Windows Calculator

One of the most commonly used DOS commands is DIR. The DIR command allows you to view a list of files that are on the disk, and also, to view which files and folders are on what disk. You are also able to view total file count, count of the directories, and all the sizes. You will also find the date and time column useful.

C:\>dir

dir command
dir command

At this point you probably have a bunch of text on your screen right now. What to do? Thankfully, DOS has a very handy command called CLS. Type CLS into your command prompt and hit enter right now. It clears up the screen. You will find this command very useful when playing with your command prompt.

C:\>cls

Back to the DIR command. If that list is too long for you, the DOS allows you to type DIR /p. Yes, just add a /p to the end of that. At this point remember that some of the DOS commands, batch specific commands, and filenames are in capital letters. DOS commands and / or parameters may or may not be case-sensitive.

C:\>dir /p

Performing the command above will display the directory listing but will pause after each screen of information. You will then be told to Press any key to continue… and when you press any key, the next group of information, if any, will be shown.

To see a list of filenames only put a /w as an alternative to the /p. The w stands for Wide and gives you a column name-only list display.

C:\>dir /w

dir /w
dir /w

You are able to view any drive on your computer. To view the listing for a floppy drive enter:
C:\>dir a:

To see the contents of your CD / DVD / Memory Card:
C:\>dir d:

The letter A was the most commonly used drive letter for the floppy drive. This works for other forms of removable storage as well such as flash drives and usually starts with letter D.

Note about dir /p. More universal way of ‘pausing’ long lists, is to use DOS command more. Try to enter the following and see whats happen.

c:\>dir | more

And to see more parameters (or also known as arguments or switches) use the question mark:

c:\dir /?

Next article tomorrow. Click here for the previous article – MS-DOS (cmd.exe) prompt introduction.

This article is from our Febooti archive, it was relevant then, and I think that it is still relevant today (a few details changed).

Edit Sep 19, 2014: added link to the Next article.

MS-DOS (cmd.exe) prompt introduction

This article is from our Febooti archive, it was relevant then, and I think that it is still relevant today.

If you remember the computers of an earlier day then you surely remember the old MS-DOS. If you are of the more recent generation of computer users then you have also probably seen, used or at least heard of MS-DOS. If you are not one of the aforementioned, MS-DOS is an acronym for Microsoft Disc Operating System. This is just yet another Microsoft operating system.

However, unlike the Microsoft operating systems, you are probably used to, Microsoft Windows 95, XP, Windows 7 or Windows 8, for example, you won’t see any neat little graphics to which you are able to click. These newer operating systems are often times called Graphical User Interfaces, or GUI. MS-DOS does not care about anything called an icon, wallpaper or screen saver. Rather than being considered as a Graphical User Interface MS-DOS is what is known as a command-line interface (CLI). You type commands on what is called the command line.

When using a command-line operating system, you enter commands to accomplish tasks. Once you have worked with this type of system you would soon realize that there are many command combinations that you enter frequently. This is where the use of batch files becomes ingenious in that when you want the computer to perform a given combination of commands an abundant number of times, a batch file can store the details of that command combination for swift execution.

Therefore a batch file is a sequence of commands you would typically enter in a command prompt. Batch files are often used to start programs and run utilities. This is because batch files can allow these events to happen with fewer commands. Automation is possible as well to further the advantages of batch. Batch files accomplish all of this while remaining relatively small in file size.

Now, how does this relate to Batch scripts? Once you make a script (program), it will run in this screen. Not exactly. We won’t run our scripts in the actual MS-DOS, more of a watered down readily accessible version Windows provides us. The command prompt – this is where you will see any output produced. This screen, among being called a command prompt, is often referred to as simply a DOS prompt, command line or a MS-DOS prompt.

You are also able to open and modify programs from the command prompt. When writing batch scripts you will soon become quite familiar with this screen. Since most of us are using Windows XP, 7 or 8 that will be the primary operating system for which the examples herein will be for. However when worthy, references will be made towards previous versions of Windows. So, to actually run the batch scripts we make we need to be able to access the command prompt.

Run cmd in Windows 8.1
Run cmd in Windows 8.1
Run cmd in Windows XP
Run cmd in Windows XP

How to get MS-DOS prompt? To access the command prompt you simply click the Start button in the lower left hand corner of the screen followed by clicking on the Run… option. On newer Windows 8 and 8.1, just press Windows key on the keyboard, and type CMD.exe

When you do this, a small box will appear in the lower left hand corner of the screen. To access the command prompt simply type cmd (Windows XP, Vista, 7).

The command prompt is similar to MS-DOS. The command prompt is a great tool that has many great uses. One way of harnessing those uses in one file and not having to type the command for that use each time is through a batch file.

Next article tomorrow.

This article is from our Febooti archive, it was relevant then, and I think that it is still relevant today.

Edit Oct 17, 2014: added link to the next article.

Real men don't make backups