0% found this document useful (0 votes)
29 views18 pages

Os Practical

Uploaded by

tillusahu651
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views18 pages

Os Practical

Uploaded by

tillusahu651
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

DOS COMMANDS

INTERNAL COMMAND
1. CLS:- (Clear the screen) This command is used to clear the screen or wipe out
every thing written on the screen.
Syntax:- C:\> CLS and press Enter
2. DIR:- (Directory) Dir command is used for listing files and directories present in
the current disk.
Syntax:- C:\> DIR [/switches]
Example:- C:\> DIR /P
/P Page wise
/W Widths wise
/S List all files and directory of subdirectories
/AH Display directory with hidden files
/AS Display directory with system files
/AD Display only directories present in current drive
3. VER:-(Version) Version numbers indicates that which edition of DOS we are
working on.
Syntax:- C:\> VER press enter
4. VOL:-(Volume) Displays the disk volume label and serial number, if it exist.
Syntax:- C:\> VOL press enter

5. DATE:- Display the current Date


Syntax:- C:\> DATE
6. TIME:- Display current time
Syntax:- C:\> TIME
.

File related commands


7. COPY CON:- This command gives the facility to create a new text file.
Syntax:- C:\> COPY CON <Filename>
C:\>COPY CON Rose.txt
A clock in a office can never get stolen
Too many employees watch it all the time
^Z
1 file(s) copied

After copy con we must specify a suitable file name. Press enter. Start typing the
informations of the file. After gathering the information we press ^Z (CTRL+Z)
button or F6 button to save the file. After pressing enter key computer will show a
message like 1 file(s) copied. This means that file is stored in the disk. Suppose
we don't want to save the file or we just want to abort from file creation job, then
we simply press ^C (CTRL+C) button to abort without saving the file, intend of
pressing ^Z button.
8. TYPE:- This command is used to display the contents or text of any file to the
display device.
Syntax:- C:\> TYPE <Filename>
A:\>TYPE GULAB.TXT
A clock in a office can never get stolen
Too many employees watch it all the time
9. COPY :- Copy command is used for copy any file to another location or to copy
the files to another directory. This command may also be used for copying any file
to another disk with different file name.
Syntax:- C:\> COPY <Source filename> <Target file name>
C:\>COPY ROSE.TXT ROSE.MSG
1 file(s) copied

TO copy a file from hard disk to floppy


disk
C:\>COPY Rose.txt A:
1 file(s) copied

To copy a file from Floppy Disk to Hard


disk
A:\>COPY LOTUS.TXT C:\
1 file(s) copied
10. REN:- (Rename) This command is used to change the name of any file or
directory.
Syntax:- C:\> REN <Source filename> <Target filename>
C:\>REN ROSE.TXT GULBAL.TXT
If we get successfully C:\ that means filename or directory name is get changed.
Either it will show the error message.
To changing the filename present in floppy disk
C:\>REN A:\ROSE.TXT GULAB.TXT
Note that you cannot specify a new drive or path for your destination.
11. DEL:- This command is used for erasing any file from the disk.
Syntax:- C:\> DEL <Filename>
C:\>DEL LOTUS.TXT
If it successfully erase the file from dosk then C:\> prompt will be appear, either
computer will show an error message.
Note:- /P option is used for permission before deleting the file.

Directory related commands


12. MD:- (Make Directory)- This command allows to create a new directory.
Syntax:- C:\> MD <Dirname>
C:\> MD REPORT
C:\>
Now this directory can be used for keeping various sort of reports. Under this
directory we can create another directory which is known as subdirectory.
13. CD:- (Change Directory):- We can enter or exit from any directory using this
command.
Syntax:- To access any directory
C:\> CD <Directory name>
C:\> CD REPORT
C:\REPORT>
Prompt will change with the directory name. If we keep two dots after CD
command than we will exit from the directory.
Syntax:-C:\> CD..
C:\REPORT> CD..
C:\>
14. RD:-(Remove directory):- This command is used when we want to remove any
unusable directory form our disk.
Syntax:- C:\> RD <Directory name>
C:\> RD REPORT

15. PATH:- This command is used for display or sets directories for executable
files.
Synatx:- C:\> PATH
This command display current path settings.
C:\> PATH=C:\WINDOWS\COMMAND;C:\WINDOWS\;C:\TC
this command will sets the directories windows, the command subfolder of
windows and TC folder for executable files. Operating system will look for
executable files in these directories.
External commands
1. MORE:-Using TYPE command we can see the content of any file. But if length of
file is greater than 25 lines then remaining lines will scroll up. To overcome
through this problem we uses MORE command. Using this command we can
pause the display after each 25 lines.
Syntax:- C:\> TYPE <File name> | MORE
C:\> TYPE ROSE.TXT | MORE
or
C:\> DIR | MORE
2. MEM:-This command displays free and used amount of memory in the
computer.
Syntax:- C:\> MEM
the computer will display the amount of memory.
3. SYS:- This command is used for copy system files to any disk. The disk having
system files are known as Bootable Disk, which are used for booting the computer.
Syntax:- C:\> SYS [Drive name]
C:\> SYS A:
System files transferred
This command will transfer the three main system files COMMAND.COM, IO.SYS,
MSDOS.SYS to the floppy disk.
4. XCOPY:- When we need to copy a directory instant of a file from one location to
another the we uses xcopy command. This command is much faster than copy
command.
Syntax:- C:\> XCOPY < Source dirname > <Target dirname>
C:\> XCOPY TC TURBOC
5. MOVE:- Move command is used for moving one file or multiple files from one
location to another location or from one disk to another disk.
Syntax:- C:\> MOVE <file name> <path name>
C:\SONGS> MOVE *.MP3 C:\ SONGS\OLD SONGS\

C:\>
6. FC:-(File Compare) This command is capable for comparing two set of files and
display difference between two files.
Syntax:- C:\> FC <First set of file> <Second set of file>
C:\> FC ROSE.TXT GULAB.TXT
7.CHKDSK:-(Check disk) - This command is used to check the status of a disk and
show the report of result status.
Syntax:- C:\> CHKDSK
C:\>CHKDSK

CHKDSK has NOT checked this drive for errors.


You must use SCANDISK to detect and fix errors on this
drive.

Volume JAI created 10-19-2001 7:14p


Volume Serial Number is 3E42-1907

4,203,073,536 bytes total disk space


381,988,864 bytes available on disk

4,096 bytes in each allocation unit


1,026,141 total allocation units on disk
93,259 available allocation units on disk

651,264 total bytes memory


610,784 bytes free

Instead of using CHKDSK, try using SCANDISK. SCANDISK


can reliably detect
and fix a much wider range of disk problems.
8. SORT:- This command is useful when we want to sort a file. When we run this
command the result can be get to display device or file.
Syntax:- C:\> SORT /R < Input file name> <output file name>
Suppose we have a file Player.txt which having the list of a cricket player team and
we want to sort the list of players, then we uses this command
C:\> SORT Player.txt
If we not specify the output file name then result will show to the screen.
/R- switch is used for sorting the file in descending order like from Z to A or from
9 to 0.
9. FIND:- The FIND command is used to search a file for a text string.
Syntax:- C:\> FIND "String to search" <File name>
C:\TEST>find "office" gulab.txt
---------- gulab.txt
A clock in a office can never get stolen
10. DISKCOPY:- DISKCOPY copies the contents of a floppy disk to another.
Syntax:- C:\> DISKCOPY <Drive1> <Drive2>
C:\> DISKCOPY A: B:
This command will be copy all contents of A drive to B drive.
11. ATTRIB:- Sets the various type of attribute to a file. Like Read only, Archive,
Hidden and System attribute.
Syntax:- C:\> ATTRIB [± r] [± a] [± h] [± s] <File name>
here r - for read only, a- for archive, h - for hidden, s - for hidden attribute.
C:\> ATTRIB +r Gulab.txt
This command will change the attribute of file gulab.txt to read only mode. To
remove the read only attribute we will follow this command.
C:\> ATTRIB -r Gulab.txt
12. LABEL:- If you are not happy with the volume label of hard disk, you can
change it.
Syntax:- C:\> LABEL
C:\>LABEL
Volume in drive C is JAI
Volume Serial Number is 3E42-1907
Volume label (11 characters, ENTER for none)? INFOWAY

13. DOSKEY:- Once we install doskey , our dos will star to memorize all
commands we uses. We can recall those commands using up or down arrow
keys. It also gives the facility to create macros, which creates a short key for long
keyword or command.
Key function for Doskey are given as-
UP,DOWN arrows recall commands
Esc clears current command
F7 displays command history
Alt+F7 clears command history
selects a command by
F9 number
Alt+F10 clears macro definitions
Syntax:- C:\> DOSKEY
DOSKey installed
Creating Macros:-
C:\>doskey t=time

C:\>t
C:\>time
Current time is 3:39:05.97p
Enter new time:

To list out all macros defined just type DOSKEY/MACROS at dos prompt and
press enter.
C:\>DOSKEY/MACROS
$D=date
T=time
14. FORMAT:- This command creates new Track & Sectors in a disk. Every
Syntax:- C:\> FORMAT [drive name] [/S]
C:\> FORMAT A:
this command will create new track & sectors.
C:\> FORMAT A: /S
This command will transfer system files after formatting the disk.

LINUX COMMANDS
Linux Directory Commands
1. pwd Command
The pwd command is used to display the location of the current working directory.
Syntax:
1. pwd
Output:

2. mkdir Command
The mkdir command is used to create a new directory under any directory.
Syntax:
1. mkdir <directory name>
Output:

3. rmdir Command
The rmdir command is used to delete a directory.
Syntax:
1. rmdir <directory name>
Output:

4. ls Command
The ls command is used to display a list of content of a directory.
Syntax:
1. ls
Output:

5. cd Command
The cd command is used to change the current directory.
Syntax:
1. cd <directory name>
Output:

Linux File commands


6. touch Command
The touch command is used to create empty files. We can create multiple empty files by
executing it once.
Syntax:
1. touch <file name>
2. touch <file1> <file2> ....
Output:
7. cat Command
The cat command is a multi-purpose utility in the Linux system. It can be used to create
a file, display content of the file, copy the content of one file to another file, and more.
Syntax:
1. cat [OPTION]... [FILE]..
To create a file, execute it as follows:
1. cat > <file name>
2. // Enter file content
Press "CTRL+ D" keys to save the file. To display the content of the file, execute it as
follows:
1. cat <file name>
Output:

8. rm Command
The rm command is used to remove a file.
Syntax:
rm <file name>
Output:

9. cp Command
The cp command is used to copy a file or directory.
Syntax:
To copy in the same directory:
1. cp <existing file name> <new file name>
To copy in a different directory:
Output:
10. mv Command
The mv command is used to move a file or a directory form one location to another
location.
Syntax:
1. mv <file name> <directory path>
Output:

11. rename Command


The rename command is used to rename files. It is useful for renaming a large group of
files.
Syntax:
1. rename 's/old-name/new-name/' files
For example, to convert all the text files into pdf files, execute the below command:
1. rename 's/\.txt$/\.pdf/' *.txt
Output:

Linux File Content Commands


12. head Command
The head command is used to display the content of a file. It displays the first 10 lines
of a file.
Syntax:
1. head <file name>
Output:
13. tail Command
The tail command is similar to the head command. The difference between both
commands is that it displays the last ten lines of the file content. It is useful for reading
the error message.
Syntax:
1. tail <file name>
Output:

14. tac Command


The tac command is the reverse of cat command, as its name specified. It displays the
file content in reverse order (from the last line).
Syntax:
1. tac <file name>
Output:
15. more command
The more command is quite similar to the cat command, as it is used to display the file
content in the same way that the cat command does. The only difference between both
commands is that, in case of larger files, the more command displays screenful output
at a time.
In more command, the following keys are used to scroll the page:
ENTER key: To scroll down page by line.
Space bar: To move to the next page.
b key: To move to the previous page.
/ key: To search the string.
Syntax:
1. more <file name>
Output:
16. less Command
The less command is similar to the more command. It also includes some extra
features such as 'adjustment in width and height of the terminal.' Comparatively, the
more command cuts the output in the width of the terminal.
Syntax:
1. less <file name>
Output:
Linux Filter Commands

grep Command
The grep is the most powerful and used filter in a Linux system. The 'grep' stands for
"global regular expression print." It is useful for searching the content from a file.
Generally, it is used with the pipe.
Syntax-grep [options] pattern [files]

Pratical Example of grep Command in Linux


1. Case insensitive search
The -i option enables to search for a string case insensitively in the given file. It
matches the words like “UNIX”, “Unix”, “unix”.
grep -i "UNix" geekfile.txt

Output:
Case insensitive search

2. Displaying the Count of Number of Matches Using grep


We can find the number of lines that matches the given string/pattern
grep -c "unix" geekfile.txt

Output:

Displaying the count number of the matches

3. Display the File Names that Matches the Pattern Using grep
We can just display the files that contains the given string/pattern.
grep -l "unix" *

or
grep -l "unix" f1.txt f2.txt f3.xt f4.txt

Output:

The file name that matches the pattern

4. Checking for the Whole Words in a File Using grep


By default, grep matches the given string/pattern even if it is found as a substring
in a file. The -w option to grep makes it match only the whole words.
grep -w "unix" geekfile.txt

Output:
checking whole words in a file

5. Displaying only the matched pattern Using grep


By default, grep displays the entire line which has the matched string. We can
make the grep to display only the matched string by using the -o option.
grep -o "unix" geekfile.txt

Output:

Displaying only the matched pattern

6. Show Line Number While Displaying the Output Using grep -n


To show the line number of file with the line matched.
grep -n "unix" geekfile.txt
Output:

Show line number while displaying the output

7. Inverting the Pattern Match Using grep


You can display the lines that are not matched with the specified search string
pattern using the -v option.
grep -v "unix" geekfile.txt
Output:

Inverting the pattern match

8. Matching the Lines that Start with a String Using grep


The ^ regular expression pattern specifies the start of a line. This can be used in
grep to match the lines which start with the given string or pattern.
grep "^unix" geekfile.txt

Output:

sed command
The sed command is also known as stream editor. It is used to edit files using a regular
expression. It does not permanently edit files; instead, the edited content remains only
on display. It does not affect the actual file.
Syntax:
command | sed 's/<oldWord>/<newWord>/'
Output:

LINUX COMMAND OTHER


sort Command
The sort command is used to sort files in alphabetical order.
Syntax:
sort <file name>

find Command-The find command is used to find a particular file within a directory. It
also supports various options to find a file such as byname, by type, by date, and more.
The following symbols are used after the find command:
(.) : For current directory name
(/) : For root
Syntax:
find . -name "*.pdf"

You might also like