os cmd

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 20

Practical 5: Commands used for windows.

1. How to change the directory in CMD (CD in Command Prompt)


The first command from the list is CD (Change Directory). This command enables you to
change the current directory or, in other words, to navigate to another folder from your PC.

How to go to the root of the drive, in CMD (CD\)

The first iteration of the CD command you should know is CD\. It takes you to the top of the
directory tree. To see how it works, after you open the Command Prompt, type:

cd\ … and press Enter on your keyboard. You should see how the CD\ command takes you
to the top of the directory tree. In this case, to the C: drive.

Running the CD\ command to change the directory to root

The Command Prompt is not case sensitive, meaning that you can type commands using
capital letters, lowercase, or any combination of them. The commands CD, cd, or Cd, all
work the same way.

How to navigate to a specific folder in CMD (CD path)

Going back to the CD command, now you are working on the root of the C: drive. If you
need to go to a specific folder from this drive, run the command CD Folder. The subfolders
must be separated by a backslash character: \. For instance, when you need to access the
System32 folder located in C:\Windows, type:

28
cd windows\system32\ … as shown below, and then press Enter on your keyboard.

How to navigate to a folder in CMD

How to change the parent directory in CMD (CD..)

When you need to go one folder up, use the cd.. command. Let's assume that you’re inside
the system32 folder and want to go back to the Windows folder. Type

cd.. and press Enter on your keyboard.

Running the CD.. command to go up one level in the directory tree

The effect is that your current directory changes to C:\Windows.

How to change directory in CMD to desktop (or other user folders)

What about changing the directory in CMD to a personal folder, like your Desktop or
Documents? It’s done the same way, using the CD command, but you need to know the
locations of your personal folders. In both Windows 10 and Windows 11, all user folders are
found in:

29
C:\Users\[username]\

For example, to change the directory in CMD to your Desktop, the command you’ll have to
run is this: cd C:\Users\[your_user_name]\Desktop

Change path to the Desktop folder in CMD

Similarly, if you want to navigate to another user folder in CMD, run the same command but
replace Desktop with the directory you need to get to. For example, if you want to change the
path to your Documents folder, run:

C:\Users\[your_user_name]\Documents

Change directory to a user's Documents folder in CMD

2. How to change the drive in CMD (Command Prompt)


To access another drive, type the drive’s letter, followed by :. For instance, if you wanted to
change the drive from C: to D:, you should type:

d: and then press Enter on your keyboard.

30
How to change the drive in Command Prompt

To change the drive and the directory at the same time, use the cd command, followed by the
/d switch. The /d parameter is used to change the current drive to a specific folder from
another disk volume.

For instance, if you are now on the D: drive and you want to go back to the Windows folder
from the C: drive, you should type:

cd /d C:\Windows and press Enter on your keyboard, like in the following screenshot.

Changing the drive and directory in Command Prompt

3. How to view the contents of a directory in Command Prompt (DIR in


CMD)
You can view the contents of a folder by using a command called DIR. To test it, we have
created a folder named Digital_Citizen on the D: drive, with several files and subfolders. You
can see them all in the screenshot below.

31
The contents of a folder found in the root of the D drive

The last time, our working folder was C:\Windows. To navigate to the folder mentioned
above, we have to use the command cd /d D:\Digital_Citizen. To view the contents of the
folder, type:

DIR and press Enter. This displays a list of the files and folders contained in it, together with
some details about each of them (the size and the date and time when they were last
modified).

Using the DIR command to see the contents of a directory

4. How to create a new directory with Command Prompt (MD in CMD)


You can make a new folder using the MKDIR (Make Directory) or the MD command. The
syntax of these commands is

MKDIR Folder or MD Folder

32
Let's say we need to create a new folder called Digital_Citizen_Life that is going to be placed
in the D:\Digital_Citizen folder. To do that, we need to type:

mkdir Digital_Citizen_Life

… and then press Enter, as shown below.

The MKDIR command in Command Prompt

if you want to create a folder called Digital Citizen, run the MD command like this:

md “Digital Citizen”

How to create a directory in CMD with spaces in its name

To test if it worked, use the DIR command again. The newly created folder appears in the list.

33
Using DIR to see the contents of the directory in Command Prompt

Another way to create a folder without having to go to the desired location for it is to type the
complete path of the new folder. For example, if you are working on the D: drive and you
want to create a new folder in C:, called other_stuff, type:

mkdir c:\other_stuff

… and then press Enter.

Using MKDIR to create a new directory, with a full path

When you need to create a folder with subfolders at the same time, you can use this
command:

34
MKDIR Folder\Subfolder

For instance, if we type:

mkdir Digital_Citizen_Tests\Beta\Test1

… three folders are created: Digital_Citizen_Tests, Beta, and Test1, in a tree-like structure.

Creating a folder with subfolders using MKDIR in Command Prompt

5. How to rename files and folders with Command Prompt (REN in CMD)
To rename files and folders, you need to use the REN(Rename) command. To rename folders,
type:

ren Folder NewFolderName

For example, if we wanted to rename the Digital_Citizen_Tests folder to


Digital_Citizen_Final_Tests, we should run:

ren Digital_Citizen_Tests Digital_Citizen_Final_Tests

… and press Enter.

35
Renaming folders with the REN command in Command Prompt

To rename a file, use the same command, like this:

ren filename.extension newname.extension

For instance, to rename the Digital_Citizen_Picture1.bmp file to Image0.bmp, we have to run


the command:

ren Digital_Citizen_Image1.bmp Image0.bmp

Renaming files with the REN command in Command Prompt

6. How to copy files in CMD (COPY in Command Prompt)

36
The COPY command allows you to copy files from one location to another. To use this
command, type:

copy location\filename.extension newlocation\newname.extension

For example, let's use this command to copy the Image0.bmp file from the Digital_Citizen
folder located on the D: drive to the D:\Digital_Citizen\Digital_Citizen_Tests\ folder. To
make things more interesting, we want the file to be named Testing_Picture1.gif. To do all
that, we must type the command: copy D:\Digital_Citizen\image0.bmp
D:\Digital_Citizen\Digital_Citizen_Tests\testing_picture1.gif

followed by Enter. You should also receive a confirmation of the operation, as you can see
below.

Using COPY to copy files with Command Prompt

If you are copying within the same directory, you do not have to include the path in the
command. As an example, let’s copy Digital_Citizen_Notes.txt from D:\Digital_Citizen in
the same folder, only with a different extension: let's say Digital_Citizen_Notes.docx. To do
that, we have to run the command:

copy Digital_Citizen_Notes.txt Digital_Citizen_Notes.docx

37
Using the COPY command to copy files in the same directory

7. How to copy folders in CMD, including their contents (XCOPY in CMD)


To copy a folder and its content from one location to another, use the XCOPY command:

XCOPY /s /i

Let's assume that we need to copy a folder from D:\Digital_Citizen to


C:\Backup_Digital_Citizen.

To do that, we have to run the command:


xcopy /s /i d:\Digital_Citizen c:\Backup_Digital_Citizen

The /s parameter ensures that all the directories and subdirectories are going to be copied,
except the ones that are empty. The /i parameter creates a new directory if the destination
folder does not exist and copies all the files in it.

Using XCOPY to copy folders and their contents in Command Prompt

8. How to delete files with Command Prompt (DEL in CMD)

38
The DEL (Delete) is used to delete files from the folders you have created. To delete all the
files from a folder, you can run the command

del folder

For instance, let’s say we want to delete all the files from the Digital_Citizen_Tests folder
found in the D:\Digital_Citizen directory. For that, you first open the Digital_Citizen folder in
Command Prompt and then you run this command:

del Digital_Citizen_Tests

You must confirm the delete process by typing the letter y for Yes, and then pressing Enter.

Using the DEL command to delete all the files in a directory in Command Prompt

If you need to delete a single file, use the DEL command followed by that file’s name. For
instance, to delete the file Digital_Citizen_Notes.txt from D:\Digital_Citizen, we should run
the command:

del Digital_Citizen_Notes.txt

Using the DEL command to delete a single file in Command Prompt

Here is a list of useful DEL combinations that are worth mentioning:

DEL *.DOCX

deletes all the files in the current folder that have the DOCX extension (you can use any file
extension necessary, DOCX is just an example).

39
DEL Test*.*

deletes all the files in the working folder whose names begin with Test.

DEL *.*

deletes ALL the files in the current folder.

9. How to delete a folder from CMD (RD in Command Prompt)


The DEL command cannot be used to delete folders. Therefore we must use another
command to remove any empty folder, which is RD:

RD [Folder]

We have previously deleted all the files from the Digital_Citizen_Tests folder. It is now time
to delete the directory too, by typing:

RD Digital_Citizen_Tests

Using the RD command to delete folders in Command Prompt

10. How to launch an app from CMD (Command Prompt)


To run a program from the Command Prompt, you can navigate to the folder that contains the
executable and type the program’s name. For example, if you want to launch Control Panel
using Command Prompt, go to C:\Windows\System32, where its executable is: control.exe.
Let's see how this operation is done if you were in your user directory. First of all, change the
working directory to the application's folder by typing:

cd /d c:\windows\System32\

Then, type the name of the app’s executable file:


control.exe and press Enter.

40
Launching an app from Command Prompt

Alternatively, you can also run an app from CMD directly, no matter what folder you’re
currently browsing, by specifying the app’s executable file and its full path in Command
Prompt. Opening Control Panel from the previous example would look like this, regardless of
your current directory in CMD:
C:\Windows\System32\control.exe

11. How to get help in the Command Prompt (HELP in CMD)

To access help in the Command Prompt, you can use the HELP command: ‘help’

and then press Enter. This displays a list of all the available commands, as you can see
below.

The HELP command from Command Prompt

41
If a particular command interests you, type help followed by the name of that command.
Another way to do the same thing is to type the command’s name followed by the /?
parameter. To test it, use

help cd or cd/?

to display information about the cd command. In the picture below you can see the result:

Using the HELP command or the /? Parameter to find help in command prompt

42
Practical 6: Implementation of CPU scheduling algorithms FCFS
to find turnaround time and waiting time.
First Come First Serve:

First Come First Serve CPU Scheduling Algorithm shortly known as FCFS is the first
algorithm of CPU Process Scheduling Algorithm. In First Come First Serve Algorithm what
we do is to allow the process to execute in linear manner.

This means that whichever process enters process enters the ready queue first is executed
first. This shows that First Come First Serve Algorithm follows First In First Out (FIFO)
principle.

The First Come First Serve Algorithm can be executed in Pre Emptive and Non Pre Emptive
manner. Before, going into examples, let us understand what are Pre Emptive and Non Pre
Emptive Approach in CPU Process Scheduling.

Implementation:

1 Input the processes along with their burst time (bt).

2 Find waiting time (wt) for all processes.

3 As first process that comes need not to wait so

waiting time for process 1 will be 0 i.e. wt[0] = 0.

4 Find waiting time for all other processes i.e. for

process i ->

wt[i] = bt[i-1] + wt[i-1] .

5 Find turnaround time = waiting_time + burst_time

for all processes.

6 Find average waiting time = total_waiting_time / no_of_processes.

7 Similarly, find average turnaround time = total_turn_around_time / no_of_processes.

Example:

43
1. S. No Process ID Process Name Arrival Time
Burst Time

1 P1 A 0 9

2 P2 B 1 3

3 P3 C 1 2

4 P4 D 1 4

5 P5 E 2 3

6 P6 F 3 2

Non Pre Emptive Approach:

Now, let us solve this problem with the help of the Scheduling Algorithm named First Come
First Serve in a Non Preemptive Approach.

Gantt chart for the above Example is:

Turn Around Time = Completion Time - Arrival Time

Waiting Time = Turn Around Time - Burst Time

Solution to the Above Question Example:

S. Process Arrival Burst Completion Turn Around Waiting


No ID Time Time Time Time Time

1 P1 A 0 9 9 9 0

44
2 P2 B 1 3 12 11 8

3 P3 C 1 2 14 13 1
1

4 P4 D 1 4 18 17 1
3

5 P5 E 2 3 21 19 1
6

6 P6 F 3 2 23 20 1
8

The Average Completion Time is:

Average CT = ( 9 + 12 + 14 + 18 + 21 + 23 ) / 6

Average CT = 97 / 6

Average CT = 16.16667

The Average Waiting Time is:

Average WT = ( 0 + 8 + 11 + 13 + 16 + 18 ) /6

Average WT = 66 / 6

Average WT = 11

The Average Turn Around Time is:

Average TAT = ( 9 + 11 + 13 + 17 + 19 +20 ) / 6

Average TAT = 89 / 6

Average TAT = 14.83334

45
Practical 7: Implementation of CPU scheduling algorithms Round
Robin to find turnaround time and waiting time.
In Round Robin Scheduling:
· CPU is assigned to the process on the basis of FCFS for a fixed amount of time.
· This fixed amount of time is called as time quantum or time slice.
· After the time quantum expires, the running process is preempted and sent to the
ready queue.
· Then, the processor is assigned to the next arrived process.
· It is always preemptive in nature.
· Round Robin Scheduling is FCFS Scheduling with preemptive mode.

PROBLEMS BASED ON ROUND ROBIN SCHEDULING-

Consider the set of 5 processes whose arrival time and burst time are given below-

Process Id Arrival time Burst time

P1 0 5

P2 1 3

P3 2 1

P4 3 2

P5 4 3

If the CPU scheduling policy is Round Robin with time quantum = 2 unit, calculate the
average waiting time and average turnaround time.
Ready Queue- P5, P1, P2, P5, P4, P1, P3, P2, P1
Gantt Chart-

Now, we know-
· Turn Around time = Exit time – Arrival time

46
· Waiting time = Turn Around time – Burst time

Process Id Exit time Turn Around time Waiting time

P1 13 13 – 0 = 13 13 – 5 = 8

P2 12 12 – 1 = 11 11 – 3 = 8

P3 5 5–2=3 3–1=2

P4 9 9–3=6 6–2=4

P5 14 14 – 4 = 10 10 – 3 = 7

Now,
· Average Turn Around time = (13 + 11 + 3 + 6 + 10) / 5 = 43 / 5 = 8.6 unit
· Average waiting time = (8 + 8 + 2 + 4 + 7) / 5 = 29 / 5 = 5.8 unit

47

You might also like