# DOS

## All you ever wanted to know about DOS: Copy

0

In this tutorial, we're going to talk about more essential commands to know in DOS. We're going to get a little more loose with the syntax in this tutorial so knowledge of the bare essentials is key in fully understanding this new loose syntax.

### Revised Syntax

In previous tutorials, we've typed the path to files long hand. For example:

C:\Users\Dennis> cd C:\users\dennis\documents\downloads

This is meant to under stand the syntax of the path and used to learn how the files are structured in XP, Vista, and Windows 7. The short hand version assumes that knowledge of the "file tree" is known and understood easily. The short-hand notation saves time and makes navigating through DOS more efficient. Short-hand notation is like the following:

 C:\Users\Dennis> cd music vs. C:\Users\Dennis> cd C:\users\dennis\music 

Both of these examples will take us to the same destination. The only difference is that the latter example provides the entire path to the destination (which is somewhat redundant) and the first example already assumes we're talking about a Music directory that exists in the path C:\users\dennis.

### Copy

Being graced with this "revised syntax" we can now commence and learn more commands in DOS! Our first command is an extremely useful command: copy. The most widely used command once upon a time but has been eclipsed by xcopy which has been succeeded by robocopy (Vista and 7 only).

The copy command is slightly more complex then any other command that we've gone over so far. There are more switches that can be used to dictate how the command executes and we need to write two paths. The syntax is as follows:

 C:\> Copy [switches] source [switches] [drive]

path] destination [switches] [drive]

!path] 

C:\> Copy *.* d: C:\Users\Dennis\test copy stuff.txt C:\users\dennis\desktop 

The first command will copy all files in the current directory to the D: drive. This is an unsophisticated way of creating backups of files and folders.

The second example is copying the file from the directory C:\users\dennis\test to C:\users\dennis\desktop.

#### Useful Switches

The copy command comes with useful switches that all us to define what type of file we are copying and what actions we want to take once the file is copied.

Switches Description
Source Switches There are two separate switches for source and destination
/A Indicates that the file is an ASCII Text File
/B Indicated that the file is a Binary File
Destination Destination Switches
/V Verifies that the copy was successful and done correctly.
/N Uses a short filename, if available, when copying a non-8-dot 3 name.
/Y Suppresses prompting to confirm that you want to overwrite an existing destination file.
/-Y Causes prompting to confirm that you want to overwrite an existing destination file. The prefix (-) means "not" in most cases.

#### Cool Copy Tricks

There are two cool tricks that stand out with the copy command. The first:

 C:\> copy con stuff.txt This is some text^Z 1 file(s) copied. 

The copy command when combined with con allows us to create a text file that we want to copy to the directory. the ^Z is done by pressing control+z, this saves and exits. Though, an easier way is to use the edit command.

The second trick is equally as cool and makes sense if you know xcopy or robocopy (Vista and 7 only). This trick will actually allow us to combine the contents of two files together. For example:

C:\users\dennis\test> copy stuff.txt+more-stuff.txt

This will copy the contents of more-stuff.txt and combine it with stuff.txt We can verify that the copy was successful by using the type command to view the contents of the .txt file.

## All you ever wanted to know about DOS: Copying, Renaming, Type, and Edit

1

Today we're going to talk about Copying, Renaming, Creating Text Files, and displaying what is inside files when using DOS. These tutorials assume that a general knowledge of DOS is already known. The first tutorial and second tutorial are excellent resources when learning DOS.

### Diskcopy

Diskcopy is a command that allows us to copy the contents from one floppy disk to another. This can be useful to create backups of the contents on a floppy disk. This can be useful in easily backing up content on a floppy that contains old finical records and other important documents from the golden days of 3.5" floppy disks.

C:\> diskcopy a:
This would make a copy of the disk that is currently in the a: (default floppy) drive. You should not use diskcopy for anything other than floppy drives, however.

### Rename or Ren

Rename or Ren allows us to rename files and folders. Let us start by navigating to our directory that we want to test our files in. The default directory for vista and XP will suffice for this example.

 Vista/7 C:\Users\Dennis>mkdir test

 

XP C:\Documents and Settings\Dennis>mkdir test 

The mkdir command creates a new directory in the current directory that we're in so no need to put the entire path to the new directory.

The syntax for the ren/rename is a little strange and nothing like any command previously mention before in this series. Be sure the path points to the parent directory (one level above the test directory), otherwise an error will occur. The syntax is the following:

 ren [drive]

path]

!current name] [new name] 

Example: ren C:\users\dennis\test test2 

To verify the name change actually occurred, use the dir command to view the contents of the directory.

### Edit

The edit command is a very basic text editor in DOS. This allows us to type basic .txt files without word wrap, without spell checker, without any configuration whatsoever.

There are two flavors of the edit command. There is the default blue background\white text option and then we can add a switch that makes the window and text the same as the default DOS window (black background and a light-gray text).

In order to activate the edit window, all we need to do is simply type "edit".

C:\users\dennis\test> edit

Type a few lines of text and then press file and save as.

Once the file is saved (be sure to include the file extension ".txt"), double check to make sure the file was successfully created by using the dir command.

### Type

The type command allows us to view any files created using the edit command regardless of file extension. Files encoded with Microsoft Office such as .doc or .docx cannot be viewed using the type command. The syntax of the type command is as follows:

 [Drive:]$$!path]\type [filename.file extension] C:\users\dennis\test>type dosstuff.txt  Notice that we are able to view any file extension as long as it was encoded using the edit command in DOS. If we were to view a file encoded in Microsoft Office 2007 it would look like the following: Notice the arbitrary characters that occur when we try to view documents encoded using MS Word. This is because the encoding format is something that DOS cannot read. ## All you ever wanted to know about DOS: Making & Deleting Files and Folders 0 In this tutorial we will be talking about the creation of directories, removal of directories, and deleting files within DOS. When juxtaposed with navigation, this can be a powerful ally when removing viruses, recovering data on a bad hard drive, deleting stubborn files, and accomplishing simple tasks easily and effectively. Disclaimer: I am not responsible for any mistakes you make while using DOS. These tutorials are merely for information purposes only. ### Why? Often, we might hear the question, "why would you wast time doing this in dos when you can just right-click and make a new folder or hit delete on a keyboard?" DOS is a useful tool to know especially if we're dealing with data recovery in safe mode, virus removal in safe mode, fixing a problem, or using certain 3rd party utilities like Disk Wipe. ### Making Directories Making directories is a useful tool when weeding out good files from bad, old from new, and organizing files in something like safe mode. For those that are familiar with unix commands, this will be like an old friend. The command for creating a new directory is md or mkdir, both do the same exact thing in DOS. Although we need not navigate to the directory in which we wish to put our new directory in, we can do so by using the chdir or cd command as seen in the first tutorial. Navigating to the parent directory where we will create a child directory is usually a good idea so we can easily see if the directory was created successfully. ###### Choose a Directory  C:\> cd C:\users\dennis\music C:\> cd C:\documents and settings\dennis\my documents\my music  The above line is Vista/7 and the below line is XP. Once we have chosen, we can create our directory in our music folder like the following: ###### Create the Directory  mkdir C:\users\dennis\music\test md C:\documents and settings\dennis\my documents\my music\test  Remember that mkdir and md are both legal when using the command prompt. This will create the directory called "test" in the drive C:\ with a path to users > music and then it will create the directory. One common mistake that happens is that some consider the md as a single command and then you type in the name of the directory we want to create. Allow me to demonstrate:  mkdir C:\ test //This is wrong mkdir C:\test //This is right  The first example has a space between C:\ and "test" and therefore renders the command invalid. If we take a look at a website URL, we'll see that it is almost identical. http://www.atomicpages.net/images/stripes.png is pointing to the world wide web address called atomicpages with the TLD of .net to the directory called "images" which contains a file named "stripes.png". Ironically, the only difference between a URL and DOS is the type of slash that it uses. A website URL uses a forward slash (/) and DOS uses a backslash ($$.

Applying this logic when creating a directory, we can see that it would make sense to merely continue until we reach the directory that will be created.

### Deleting Files

Deleting files in DOS is somewhat of a godsend. At times, there are files that you cannot delete regularly using the Windows GUI so we have to resort to DOS to do our bidding for us. This also can be extremely useful when combating a virus in safe mode.

Deletion of files comes in two flavors:

Del Erase
Originally, the DEL command could not have any wildcards in the parameter of the command. So del C:\ *.* /f would not work. ERASE, on the other hand, was specifically created to allow wildcards and also to erase the files.

Do NOT try del C:\ *.* /f or erase C:\ *.* /f unless you want your entire C: drive wiped clean.

There are times when either command is appropriate, however. If a directory or file is being stubborn and the del command is not working, try the erase command instead.

###### Useful Switches
/p /q /f /a
This prompts before deleting of files. This can be useful if you have to delete a small number of files but don't want a certain file deleted. Enables "quiet mode" where you are not notified to confirm deletion of any files. Useful for a large number of files. Enables a forceful deletion of files Activates attributes that can help you define which files you want to delete. Use del /? for more details.

To further illustrate the minor difference between del and erase, there once was a time where I had a Windows.old file from a clean install from Vista to 7. For the life of me I could not remove this directory. I tried viewing hidden files and folders, tried using del C:\windows.old /f tried rd C:\windows.old and then I tried the following: erase C:\windows.old /f and then finally I was able to remove the directory.

###### Using Del and Erase

A good way to practice is to go to lipsum.com and generate however many words, paragraphs, or bytes of words you want to create new .txt documents by right-clicking and selecting new from the menu in Windows. Name them different things and then navigate to our test directory and display the files within the directory via dir.

If we want to delete all of the folders, we would type the following:

 C:\> del C:\users\dennis\music\test C:\> del C:\documents and settings\dennis\my documents\my music\test

 

C:\> del C:\users\dennis\music\test\* C:\> del C:\documents and settings\dennis\my documents\my music\test\* Are you sure (Y/N)? 

Notice how DOS automatically puts \* at the end so that all files will be deleted. Erase will work and look the same as del in this situation.

#### Removing Directories

Removing Directories through DOS will save you heartache in the long run especially if the directory is one you could not delete normally through the Windows GUI.

rd or rmdir is the command we would use to remove a directory. If the directory is not empty we'll get an error like the following:

Be sure the directory is empty using the erase command and then do the following:

 C:\users\dennis\music\test\> ..\ \\brings you up one dir C:\users\dennis\music\> rd C:\users\dennis\music\test

 

C:\> del C:\documents and settings\dennis\my documents\my music\test\> ..\ \\brings you up one dir C:\> del C:\documents and settings\dennis\my documents\my music\> rd C:\> del C:\documents and settings\dennis\my documents\my music\test 

The ..\ literally brings us up one parent directory or up one level in the file tree.

That's it! Now you know how to use basic commands that allow you to create folders, delete files, and to remove folders from your hard drive.

## All you ever wanted to know about DOS

3

DOS is an acronym that stands for Disk Operating System and was the base for Windows Operating systems until Windows 2000 when Windows NT took over. When you boil any windows os down you get dos eventually. DOS, cmd.exe, or command prompt — three terms that are not all mutually exclusive — is a very powerful tool when combating viruses, formatting your hard drive, or simply copying files and folder from one directory to another.

Please note: directories are different in XP and those examples will be clearly indicated with a line below the Vista and Windows 7 directories. So if you're a faithful XP user, your command line is below the divider.

Note: All commands used in this tutorial series work on XP, Vista, and Windows 7.

In this tutorial, we will be going over basic DOS navigation commands. So let us begin already!

C:\> is how we often identify CMD from something like Windows Power Shell or a Unix Terminal.

This is an example of Windows Power Shell explaining foreach loops

### Why would we use CMD?

There are a number of reasons why we would use CMD. Often, we use CMD to view network statuses, open Windows Utilities like System Configuration, or to delete stubborn files that we cannot delete normally.

Note: if you are using Vista or Windows 7, you will need to open cmd.exe as an administrator. This is called an elevated cmd where you start in the System32 directory and cmd.exe has full admin privileges.

### Navigating Through DOS

Navigating through the command prompt is very easy and powered mostly by one simple command: cd.

cd or chdir stands for Change Directory. This allows us to change directories (or folders) in DOS. For example:

Let us assume we just opened the command prompt and we wish to navigate to the root directory of our C: drive. In order to do this we would do the following:

cd C:\

This is telling DOS to change the directory to C:\ or the root directory of the Hard Drive.

Using a bit more complex directories, we can navigate to our music folder from the root directory (C:\>)

 C:\> cd C:\users\dennis\music - VISTA/7 C:\> cd C:\documents and settings\dennis\my documents\my music -XP 

Note: when using CMD, the commands and any text you write are NOT cap-sensitive. There is no difference between CHDIR and chdir, they both will work.

If we got lost in here, fret not. This brings us to our next command which is dir which stands for directory. A directory is any really just any old folder on your hard drive. This could be the Windows directory, the System32 directory, or the Music directory.

The dir commands shows us all of the directories and files within the directory we are in. Let us assume we're back in the root directory of our C: drive and we want to see all files and folders within the C: directory we would simply type:

C:\> dir

VISTA / 7 XP

We can see that there are many folder within the root directory of our C: drive. The Windows folder contains our operating system, the user folder contains out user accounts and personal files, and the Program Files contains all of our applications.

### Switches

If you are familiar with programming then you are familiar with functions (methods for those java programmers). In DOS we have what are called switches. These switches or arguments, allow us to have a command do something specific or only do part of the command. For example,

 dir |more dir /4 taskkill /im iexplorer.exe /f erase C:\windows.old /f rd C:\windows.old /q /s 

The forward slash / designates the switch used for the DOS command.

#### The most important switch of all

By far the most important switch to know is /?. Confused a little? The /? switch allows us to get help with any command. Using this siwtch on a command will show us the syntax, all of the siwtches that can be used, and often it will show examples of the command in use. For example,

dir /?

Using this switch, we can figure out all other switches and easily determine what we need to do. If, for instance, we wanted to show the directories and files that end with .sys except, we want them in alphabetical order, we would do the following:

dir *.sys /on

This will find all files that end with .sys and place them in alphabetical order. The switch /on can be separated into two components first.

/o /n
Enables the sortorder switch. This allows you to sort the order of the directories you are searching through The subswitch — so to speak — is like an extension of the sortorder switch. Since it's a subswitch, we can negate the / before the n.

#### Wildcard

You may have noticed the asterisk before the .sys. This is called a wildcard. If you've ever done programming of any kind of are proficient in CSS, then you may have encountered this wildcard before.

Basically, a wildcard is something that allows you to do something or apply something to multiple things without having to define them all directly. This can be important when navigating through DOS. If, for instance, we're looking for a .exe file but we don't know the name of it or even if you know part of the name, then we can use the wildcard to find it. COnsider the following:

 C:\users\{username}\documents\pictures> dir n*.jpg 

This will search through the entire picture folder for images that start with n and end in .jpg.

#### Question Mark Wildcard

The question mark is another form of wildcard with DOS. The difference is the number of character that can be used for each wildcard. The Asterisk (*) will allow up to an eight character substitution and the question mark (?) will allow for a single character substitution. For example,

C:\Windows\System32\> dir x*.e?? /on

This would search for any files and directories that begin with "x" and end with the file extension that starts with an "e". These results would also return alphabetically via the switch "/on" as mentioned before.

Go to Top