DOS commands

DOS cheat sheet

Today I am going to tell you the basic DOS commands. Here is the cheat sheet of DOS basic commands.

How to create the file from the dos prompt?

Creating a file from the dos prompt is easy using copy command you can create the file in dos. We will use a DOS device file called CON (console). The copy command is used to create a file.

C:\> COPY CON filename.txt
This is my file
^Z

This command will create a filename.txt file and save it in c drive.

How to view content of the file in DOS?

Using type command we can view the content of the file.

C:\>TYPE filename.txt

The content of the non-textual file contains machine code. Displaying this type of file will not be very helpful.

How to create a duplicate file using command?

The COPY command can be used to make a duplicate of the original.

c:\>COPY filename.txt otherfile.txt

This will create a duplicate of filename.txt and name it Otherfile.txt. Using DIR command you can check the duplicate file otherfile.txt.

How to delete the file from DOS Prompt?

Using DEL command, we can delete the file.

C:\>DEL filename.txt

This will delete the file without asking you. If you want that system will ask to confirm than use \P Parameter in it

C:\>DEL /p filename.txt

What are Wildcard Characters in DOS?

Wildcard characters are those characters that are used for substituting one character or a set of characters. There are two types – ‘*’ and ‘?’ where ‘*’ can substitute a set of characters and ? can only substitute a character at a particular position.

Examples

  • To view all text files
    C:\>DIR *.txt
  • To view file started with P only
    C:\>DIR P*.*
  • To view files whose last character is not known
    C:\>DIR filename.tx?

DIR parameters

DOS dir has one or more qualifiers to make the command more specific. The qualifiers are called parameters. some of them are given below

DIR <filename> /W /P /B /O:sort order

/W [wide] parameter tells DOS to display only filenames and extension in five columns across the screen.

/P [pause] parameter tells DOS to display the entries on the monitor. one screenful at a time. and ask you to ‘Press any key to continue’

/L parameter can be used to convert the display of the directory entries from upper case to lower case.

/O:<sortorder> parameter tells DOS to arrange the directory by name, size, extension, date and time

Example

  • DIR /O:N sorts the files alphabetically[a-z] by filename
  • DIR /O:-N sorts the files in descending order[z-a]
  • DIR /O:E sorts the files alphabetically by extension
  • DIR /O:-E sorts the files in reverse order by extension
  • DIR /O:S sort by size
  • DIR /O:D sort by date
  • DIR *.doc /s command not only displays the files with extension doc from the root directory, but also from all the subdirectories present in all the level below the root.

How to print a document from DOS Prompt?

Using copy command you can print the document.

C:/COPY filename.txt PRN

DOS sends all the file to the printer and when done DOS display the message 1 file copied.

How to merge the text files in DOS?

we can use the + symbol to combine several files into one file using the COPY command.

C:\>COPY filename.txt + otherfilename.txt newfile.txt

This command create a new file newfile.txt, which has the content of both files.

How to rename a file in DOS?

Using REN command we can rename the file.

C:\>REN <oldname.txt> <newname.txt>

CHKDSK command

The CHKDKS command allows you to find out if your disk contains chains of lost clusters. When DOS writes information to your disk. an error can occur. Although it is rare, CHKDKS command can help you in correcting these errors. IT will examine your disk and display the following information:

  • The total amount of space on the disk.
  • Disk volume name
  • The no of files and directories and disk space occupied
  • Disk space free for storage
  • Disk space consumed by bad sectors
  • Total no of allocation unit and each unit’s size
  • The size of the compute’s memory and how much is free for use

C:\>CHKDSK C:

C:\>CHKDSK C:*.* /V
The third parameter /V displays the name of each directory and file on the disk.

C:/>CHKDKS C: /V /F
The fourth parameter tells DOS to correct any errors it finds in the directory. CHKDSK displays the following message if it detects an error:

nnn lost clusters found in n chains.
Convert lost chains to files(Y/N)?

PATH

C:\

Backslash [ \ ] given above refers to the root directory and anything that appears after backslash represents subdirectory. The entire name with the drive name followed b the subdirectory name is referred to as a pathname or path. DOS locates files based on this path.

C:\>PATH = C:\DOS;C:\WS5;

Each time you type in a command at the MS-DOS prompt, DOS first checks to see if the command is one of the internal commands that it always keeps in memory. If it is, DOS executes the command, IF it isn’t. DOS searches the current directory specified in the given command. If DOS finds the command as an external command or file, DOS executes it. Otherwise, DOS displays the following message:

Bad command or filename

The path command tells DOS where to look for the command file if it’s not in the current directory. The DOS PATH command allows you to specify several subdirectories that DOS will travel in search of your external commands.

C:\>PATH = C:\DOS;C:\WS5

Subdirectories

MKDIR or MD

To DOS, a subdirectory is simply a file that contains directory entries. These entries are similar to entries in the main directory. The root directory is denoted by backslash (\). This directory is created by DOS when the disk is formatted. The users can create directory The MKDIR, or MD creates subdirectory.

C:\>MD programs
C:\>MD database
C:\>MD Spreadst

Three directories will be created in the root \ directory.

CHDIR or CD

The change directory command changes or displays the name of the current directory.

C:\>CD programs

you will get

C:\programs\>

. and .. directories

The single dot ].] represents the address of the current directory and double dot[..] represents the directory that contains the current directory, referred to as the parent directory of the current directory.

C:\programs\>CD..

you give the jump to the root directory

C:\>

RMDIR or RD

THE RD or RMDIR command removes the subdirectory. A subdirectory cannot be removed if it is not emptied of files or if it still contains subdirectories of files.

C:\> RD programs

This will remove programs subdirectory.