Saturday 28 June 2014

DOS COMMANDS

DISK OPERATING SYSTEM (DOS)
INTRODUCTION
DOS is an Operating System. It works as an interpreter between user and computer. We give
English like commands and it converts it into machine language and after the computer has
processed the information, returns the results to you in English. Ms. Dos consist of four essential
programs and a set of additional utilities.
Components of MS-DOS
MS-DOS consists of four essentials programs and a set of additional utilities. Four main
programs are
·          Boot Record
·          IO.SYS
·          MSDOS.SYST
·          COMMAND.COM
Booting: Process that starts up a computer is called booting. It checks for proper functioning of
all the peripheral devices attached with the system. It searches for the operating system and,
when located, loads it into the main memory. See fig.01.
Cold Booting is done by turning on the computer.
Warm Booting is performed by pressing Ctrl+Alt+Del keys simultaneously.
There are two name in DOS and is divided into 2 parts.
1. Primary Name
2. Secondary or extension.
Primary name is separated from the Secondary name extension with the help of a dot (.) look at
the following example.
Example: ENVOICE. TXT
Primary name can be from 1 to 8 characters long and
Secondary name contains 3 or less than 3 characters and is optional. The extension tells DOS
about what kind of file it is.
A valid Character for naming a file are: from A to Z and the digit 0 to 9
C :\> Is known as DOS/command prompt, where we give the commands.
DOS command divided into 2 parts.
1. Internal Commands or Memory-Resident Commands
2. External Command or Disk-Residence Commands
INTERNAL COMMAND
There are also called memory-resident commands. These commands are automatically loaded
into the computer’s memory during the booting process. They actually included in the
Command.com file. So these commands are executable immediately after getting the dos
prompt.
A few internal commands are


01. VER
02. VOL
03 DATE
04. TIME
05. CLS
06. DIR
07. MD
08. CD
09. PATH
10. RD
11. COPY CON
12. TYPE
13. COPY
14. DEL
15. REN
16.PROMT


A command can be given in Capitals or Small letters also. The internal commands can
execute immediately but External Commands require special files for their execution
without which it is not possible to execute them.
1. VER: - All O/S has its own edition number or release or version number. The version
number indicates which edition of O/S you are working on.
Syntax:    VER <Enter>
Example:    C:\> Ver <Enter>
output: -  Microsoft Windows XP [ Version 5.1.2600]
02. VOL: - It is used to display volume label and serial number of the current drive
Syntax:  Vol [drive:]
Arguments:
·               Drive: This command-line argument specifies the drive letter of the disk for which to display the volume label and serial number.

Example:  C:\> VOL c:
Output:
C:\Users\root>vol C:
Volume in drive C is Vista
Volume Serial Number is 080F-100B

3. DATE: - Used to display the current system date and prompt for entering new date.

DATE is a command in DOS, OS/2 and Windows. This command is available in command line interpreters (shells) such as COMMAND.COM, CMD.EXE, 4DOS, 4OS2 and 4NT.

 

Syntax

The syntax differs depending on the specific platform and implementation:

DOS

DATE 
 
This command will display the date and wait for the user to type a new date and press RETURN

Windows (CMD.EXE)

 DATE [/T ]
The parameter '/T' will bypass asking the user to reset the date.
The format of the date parameter is dependent upon regional settings.
 
DATE [/T] [mm-dd-yy]
 
/T:  (Display only)
mm:  The month (1–12).
dd:  The day (1–31).
yy:  The year (00–99, or a 4-digit year).
 
Examples :
·         To display the system date and prompt for entering new date.
[C:\]DATE
Current date is: Wed  2.12.2010
Enter the new date: (dd.mm.yy)
·         To display the current system date without prompting for entering new date.
C:\>DATE /T
11.16.82

4. TIME: - Displays the current system Time and prompt for entering new time.
·         To display  the current system Time and prompt for entering new time with the format hh:mm:ss:xx.
hh:hours
mm:minutes
ss:seconds
xx:100th of the second

Syntax:   C:\> Time
Output:
 The current time is : 15:59:08:18
Enter the new time:_
 Either type a new time and press enter
 or press enter without typing any time to leave the same time
·         To display the current system Time without prompting for entering new time.
Syntax: :          C:\> Time  /T
Output:            03:59  PM
5. CLS: - Clears the screen.
Syntax: CLS <Enter>
Example: C:\> CLS <Enter>
6. DIR: - This command displays the list of directories and files with details like date of
creation whether it is directory or file etc.
Syntax: C:\> DIR
Switches:
/p : To view one screen of files at a time.
/w : Displays only five column of filenames and directories.
/b : Display only file and directory.
/l : Display all the information in lower case letters.
/a — stands for attributes that are given below.
/-h - Hidden ( or not hidden) files
s/-s - System ( or not systems) files
d/-d - Directory ( or not Directory) names
r/-r - Read only( or not read only) files
Example:
C:\>DIR

output:
 Volume in drive C has no label.
 Volume Serial Number is 8C87-FFA1

 Directory of C:\

04/21/2006  04:42 PM    <DIR>          Batch
04/18/2006  12:06 AM                 0 CONFIG.SYS
04/21/2006  07:45 PM                 32 dir.txt

 2 File(s)             32 bytes
               3 Dir(s)  196,047,323,136 bytes free


C:\>DIR *.txt                                         Display all the files with extension .txt
C:\>DIR D???.*                                  Display all the files starting with D and
                                                               having less than or equal to four characters
                                                             in the file name and any extension.
Here “?” And “*” are called “wild card character”.
“*” Stand for any number of the character
“?” Stands for nay one character.
07. MD OR MKDIR: -Used to create a new Directory or nested Directories.
Syntax:    MKDIR OR MD [DRIVE:] PATH DIRECTORY NAME
Example: C:\> MD SAMS
08. CD OR CHDIR: - This command allows you to change present directory to another
directory.
Syntax: CD [DRIVE:] PATH
Example: C:\> CD SAMS
8). CD or CHDIR  (Change Directory) is an internal command used to switch between directories in MS-DOS
Syntax
Windows XP and later
CHDIR [/D] [drive:][path]
CHDIR [..]
CD [/D] [drive:][path]
CD [..]
..                   Specifies that you want to change to the parent directory.
 [ drive:]       to display the current directory in the specified drive.
 CD               without parameters to display the current drive and directory.
 /D                switch to change current drive in addition to changing current directory for a drive.
Windows 98 and earlier syntax
CHDIR [drive:][path]
CHDIR[..]
CD [drive:][path]
CD[..]

Examples
cd\
               Goes to the highest level, the root of the drive.
cd..
               
               Goes back one directory.
                For example, if you are within the C:\Windows\COMMAND> 
                directory, this would take you to C:\Windows>
 Summary:
CD..   (Work your way down a path)
CD\    (Take you right to the root of the drive)
CD NameOfDirectory\NameOfSubDirectory    (Work your way up a path)
CD     (When used on its own it just displays the current path)
Switching Between Drives
This is very easy as all you have to do at the Command Prompt is type the following and press "Enter"
D:   (After typing D: press the "Enter" key to switch to D Drive)
E:   (After typing E: press the "Enter" key to switch to E Drive)
F:   (After typing F: press the "Enter" key to switch to F Drive)
C:   (After typing C: press the "Enter" key to switch back to C Drive)

09. PATH: - This command defines a list of directories DOS Searches for external
            commands.
PATH [ [drive:] path[;...] ]
PATH ;
 
Type PATH ; to clear all search-path settings and direct DOS to search
only in the current directory.
 
Type PATH without parameters to display the current path.
 
10. RD: - To delete the empty directory.
Syntax: RD [DRIVE:] PATH
NOTE: -The directory must be empty when we use RD.
Example: C:\> RD SAMS
Switches: - 1.          /s – Remove with subdirectories and files.
      2.          /q – Don’t ask to confirm.
11. COPY CON: -We use this command to create a new file.
Syntax: COPY CON  <FILENAME>
Example: C:\> Copy Con sams.txt
Note: - Typing here and when you are done, press Ctr+Z or F6 key followed by Enter to
save the current document.
12. TYPE: - This command allows you to see the contents of an existing file on the
screen.
SYNTAX: TYPE [DRIVE: ]  [PATH] <file name>
  [DRIVE: ]    Specifies the drive the file is stored
[PATH]           Specifies the path of the file
<file name>  Specifies the name  of  the file
Example: C:\> TYPE SAMS
13. COPY: - Using this command we can make duplicate files of an exiting file from one
location to another or one directory to another with different name or exiting name.
SYNTAX:
C:\> COPY  < SOURCE FILE NAME>  <TARGET FILENAME>
 C:\>COPY [/A | /B] source [/A | /B] [+ source [/A | /B] [+ ...]] [destination [/A | /B]] [/V] [/Y | /-Y]
 
  source       Specifies the file or files to be copied.
  /A           Indicates an ASCII text file.
  /B           Indicates a binary file.
  destination  Specifies the directory and/or filename 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).
/Y and /-Y are only available in DOS 6 and above.

Example: C:\> COPY SAMS.TXT A:\TAJ
Example: C:\> COPY*.TXT +*.BAK TARGET FILENAME And Then Press Enter
Example: C:\> COPY SAMS.TXT C:\SAMS_1\FO\RECEPTION And Then Press Enter
You can also have the option to change the name of files as you copy it.
Example: C:\> COPYold.TXT C:\dos\new.txt And Then Press Enter
14. DEL / ERASE: This command removes one or more files from the disk or current
working directories.
SYNTAX:   DEL filespec [/p]  [/q] or ERASE filespec [/p] [/q]
Example:   C:\> DEL C:*.BAK /P And Then Press Enter
Example:   C:\> DEL abc And Then Press Enter
Example:   C:\> DEL ????.COM And Then Press Enter
Switches:      filespec    Specifies the file name
         /p              confirmation
                      /q               In quit mode
15. REN: Used to change the name of the file or directory.
SYNTAX: REN <file name>
Example: REN sams sams1 <Enter>
Example: REN *.dat *.mst And Then Press Enter
16 PROMPT: This command allows you to customize the dos prompt.
SYNTAX:   PROMPT
 Some special $ parameters are given below.
Character                     example description
$Q                   = Equal Sign
$$                    $ Dollar Sign
$t                     12:30:06:92 Display current time
$d                    tue 09-07-2007 Display current date
$v                    msdos version 6.2 show dos version number
$g                    > Greater than sign
$L                    < Less than sign
Most people like to set their prompt to $p$g which display the current directory followed
by > sign.
Example: PROMPT $P$G <Enter>
17. TREE: - It is used to display directory structure of a specified directory graphically.
Syntax : TREE [drive:] [path] [/f]
[/F] : displays the names of the files in each directory.
EXTERNAL COMMAND:
These are also called Disk-Resident Commands. These commands are meant for
special purpose. These are found in separate files on Hard Disk or Floppy Disk, So that
they don’t typically consume valuable memory space. They are loaded into memory only
when called.
Some External Command are:


1. Xcopy
2. Move
3. FC
4. Doskey
5. Mem
6. FILTER
   a.. More
   b.. Sort
   c Find
7 Attrib
8. Deltree
9 Edit
10 Tree


1. XCOPY:  This command is faster than Copy Command and allows you to copy
entire directories/disk including all the sub directories and files to destination.
Syntax:         XCOPY Source [ Target][/Y][-Y] [/P][/E]
SWITCHES :
/-Y : Prompts before copying over existing files.
/y : Overwrites existing files without prompting.
/p : Ask before copying each file.
/e : Copying empty directory also.
/s : Copying subfolders.
EXAMPLE:   XCOPY   C:\SAMS   D:\SAMS /S/E
2. MOVE : This command moves a file or group of files from one directory to
another and also one disk to another disk. It can also be used to rename directories.
SYNTAX: Move [Path File Name] [Destination file name path]
SWICHES:
/-Y : Prompt before it overwrites while it copies file that already exists.
/Y : Overwrites existing files without prompting.
EXAMPLE: move c:\sams\fo.txt to d:
EXAMPLE: move c:\sams\fo.txt to d:\ new_sams
3. FC: Stands for File Compare. Compares two files or two sets of files.
           This command has the capability to differentiate between the files and display the
            difference
SYNTAX: FC  <files spec 1>  <files spec2>  [/a] [/b] [/c] [l] [/n]
Switches
/a : This switch displays only the first and last line of each group.
/b : Compare the files in library mode ( byte-by-byte)
/c : Ignore the case of letters.
/l : Compare the files in text mode.
/n : Displays the line number for lines that are different.
EXAMPLE: FC first.txt second.txt\n and then Press <enter>
4. DOSKEY: Dos can remember only the last command you had entered. But in order to
make DOS remember all the commands you enter you will have to load a DOSKEY
utility. Also DOSKEY is Used To Create Macros
Syntax: DOSKEY and Press <Enter>
Display message on the screen.
DOSKEY Installed.
NOTE: - To display all commands from the history list on the screen.
Example: DOSKEY / History or /h < Enter>.
Now when DOSKEY is in memory, it can help store all the commands which you
enter so that any of those commands need not be typed again to be executed.
And this list is called HISTORY LIST. Now when you want the same command to
be done you can use up, down  arrow key or ‘F1’ or ‘F3’ Issuing following command.
Second feature of DOSKEY is Doskey Macro. Using this macro you can create own
command and latter you can run it on the system prompt. For example
EXAMPLE: - DOSKEY C= CLS
Now if you type at the system prompt only C and press enter it will clear the screen.
Recalling Commands: Some key is provided to recall recent commands you have run
since installing DOSKEY.
Key Strok              Effect
Up Arrow              Display the Preceding Command and further list.
Down Arrow        Show the next command you executed after the one that’s being
                             displayed.
Page Up                Display the oldest command that is still in Doskey.
Page Down           Show the most recent command that you executed
F7                    Display the entire list of command that you executed.
F9                    Selects a commands
Alt+F7            Erase the command history list.
Alt+F10          Erase all macros in memory
Esc                  Clear the command line.
Ctrl-T              Command separator
5. MEM:
This command displays amount of total available memory ( low, Expanded and
Extended) and all currently programs.
Syntax: MEM [/f] [/p] [/m]
Switches:
/f      : Using this switch MEM display all the areas of memory that are free.
/p      : Display the information one screen at a time.
/m     : Display information about how a specified program is using memory.
Example: MEM /p and then press <Enter>
6. FILTER:
A Powerful feature of DOS is its use of filters to process data directly. A DOS FILTER
can process in unique way any data that passes through it and can change what we see
on the screen.
There are three FILTERS include in DOS.
A. MORE: More command used to pause vertical Scrolling on the display screen,
after each screenful.
The display pauses and the message - - More - - appears.
Pressing any key display the next screen.
EXAMPLE: C:\> MORE < TYPE FILE.TXT and then press <Enter>
EXAMPLE: C:\> DIR /MORE and then press <Enter>
B. SORT: Reads, Sorts in Order and sends the data to the screen, file or to another
device. Sort to arrange data in an order.
SYNTAX:  SORT  [drive:] [Path] [filename] [/r] [+n]
Switches:
[drive:][Path][filename] : Specifies the name and location of the file to be
                                          searched. It must be preceded by the redirection
                                         character (<).
[/r]            : Sort lines in reverse ASCII Order ( Z-A)
[+n]           : Sorts line starting with the contents in column n. The default is 1.
EXAMPLE: C:\> SORT < NAME .TXT and then press <Enter>
EXAMPLE: C:\> SORT /+20 < PHONE .TXT and then press <Enter>
Note: Sort command doesn’t distinguish between upper and lower case. It can sort file
of maximum 63 k size.
Combining Input & Output redirection :
EXAMPLE: C:\> SORT < NAME .DAT > SORTNAME.DAT and then press <Enter>
Here the sort command is being directed to take its input from <name.dat and after
sorting, send its output to the > sortname.dat file.
C. FIND: The find Filter is used to search a file one or more designated character (called
a text string) Depending upon the form of the FIND Command. Each line having (or not
having) the text string is sent to an output devices, such as the Screen, a file or the
printer. The text string is always typed within quotes ( “Text Sring”).
SYNTAX: FIND [/v][/c][/n] “String “ [d:] [path][filename]
Switches:
[/v]   : Displays all the lines that do not contain string.
[/c]   : Display the total number of lines found to contain the string.
[/n]   : Display the line number as well as the line that contains the string.
[/i]   : Ignores uppercase or lowercase during the search.
Where:
  “String” : Specifies one or more alphabet or numeric character whose maximum
   length should not be more than 250 characters and must be enclosed in double   
   quotes.
[d:] [path][filename] : Specifies the name and location of the file to be searched .
EXAMPLE: C:\> FIND “Rajni” my.txt per.txt and then press <Enter>
7. ATTRIB:
Every File on the Disk has its own description like size, space occupied, the type, the
date it was created, etc. Likewise, every file has few attributes. The attributes of a file
indicates whether it is a
i) Read-Only File: r ii) Archive File a
iii) Hidden File: h iv) System File s
With the ATTRIB command you can check the attributes of a file.
SYNTAX: ATTRIB [+r][+a][+h][/+s] [filename]
Switches:
+r, -r    : +r Read-Only attribute or, -r turn of Read-Only attribute
+a,-a    : +a archive attribute, or -a turn of archive attribute
+h,-h    : +h hidden attribute, or –h turn of hidden attribute
+s, -s    : +s system attribute and it should not be used generally.
Note:
While Creating a new file every file gets read only attribute and archive attribute by default.
EXAMPLE: C:\> ATTRIB   my.txt +R    and then press <Enter>
EXAMPLE: C:\> ATTRIB   my.txt +H    and then press <Enter>
8. DELTREE:
This command used for deleting an entire directory whether in that directory contains
files or subdirectories and also it will delete hidden files.
Syntax: DELTREE [drive:][path] directories [/y]
EXAMPLE: C:\> DELTREE my.txt and then press <Enter>
9. EDIT:
This is the DOS Editor, which you can use to edit the text file and also creating new file.
Syntax: Edit [drive:][path][filename]
EXAMPLE: C:\> EDIT   c:\sams\FO.TXT    and then press <Enter>
EXAMPLE: C:\> Edit  NEW FILE     and then press <Enter>
10. TREE
Allows the user to view a listing of files and folders in an easy to read listing.
Syntax
         TREE  [Drive:] [\ Path] [ /f]
Drive:\Path
Drive and directory containing disk for display of directory structure.
/f
Displays file names in each directory.

Examples
C:\> tree
List a tree listing of the current drive. Below is a basic example of what a directory may look like.
C:.
├───Common
├───Director
├───Flash
├───Shockwave 8
│ ├───DswMedia
│ ├───Prefs
│ └───Xtras
└───update

BATCH FILES
It is a collection of DOS commands to perform a certain task. or A batch file is nothing
but sequence of commands to perform sequence of operations step by step without user intervention.
Look at the following commands you give step by step to perform an operation.
Suppose your job is
First - Check the directory
Second - Copy a file called ABC.txt to another disk
Third - Delete ABC.TXT from the present disk
Fourth - Clear the screen
 
i) C:\> DIR <Enter>
ii) C:\> COPY C:ABC.TXT D: <Enter>
iii) C:\> DEL ABC.TXT <Enter>
iv) C:\> CLS <Enter>
 
How to create a batch file:
C:\> COPY CON A.bat <Enter>
Note:
Here Con means Console that is Keyboard, A the file name and .bat is extension.
It is compulsory that a batch file must have extension .BAT.
You will find the cursor below ‘A’ now type
C:\> DIR <Enter>
C:\> COPY A.TXT D : <Enter>
C:\> DEL A.TXT <Enter>
C:\> CLS <Enter>
Now Press the F6 or Ctrl+Z key combination. You shall find ^Z symbol below CLS, Now
press Enter. You will receive the following message
1files Copied.
And you are returned to the prompt C:\>
Now to execute the Batch File simply type the name of the file.
C:\> A <Enter>
You will see all the commands in the file A.bat come right into action. So instead of typing
all those command one after another performed the same job by just typing the file
name A.