Module 2
Module 2
Module 2
Introduction
Commands, in the context of computing and programming, refer to specific instructions or
actions that a computer or software program can understand and execute. These commands are given
by users or scripts to perform various operations, manipulate data, control the system, and interact
with the computer's resources. Commands are an essential part of operating systems, programming
languages, and command-line interfaces.
Objectives
1. Performing Operations
2. Displaying information
3. Setting and Manipulating Variables
4. Conditional Execution
5. Repetitive Execution
6. User Interaction
7. Input/Output Redirection
8. Error Handling
9. Calling External Programs
10. Modularity and Reusability
11. Environment Interaction
Performing Operations
Commands in batch scripts are used to perform various operations, such as copying
files ( ‘copy ’ ), moving files and directories (‘ move ’), deleting files and directories ( ‘ del ’
and ‘ rmdir ’ ), creating directories ( ‘ mkdir ’ ), etc.
Example of copy command: Example of move
command:
Displaying information
Commands like `echo`, `type`, and `dir` are used to display information, such as messages,
text, and file directory listings, respectively, during the execution of the batch script.
Setting and Manipulating Variables
Commands like `set` and `setlocal` are used to define and manipulate variables within the
batch script. Variables allow you to store and retrieve data, which is useful for carrying out
conditional operations and maintaining state.
Conditional Execution
Batch scripts often utilize conditional statements like `if` to make decisions based on certain
conditions. These conditions can determine whether specific commands or blocks of commands
should be executed or skipped.
Repetitive Execution
Commands like `for`, `while`, and `goto` enable repetitive execution of commands. For
example, a `for` loop can iterate over files in a directory to process them one by one.
User Interaction
Commands like `set /p` and `choice` enable user interaction by allowing the script to prompt
the user for input or to present choices with selectable options.
Input/Output Redirection
Redirection operators (`<`, `>`, `>>`) and pipes (`|`) allow batch scripts to handle input and
output from/to files or other commands. This enables reading data from files, writing data to files, and
combining the output of one command as input to another.
Error Handling
Batch scripts can handle errors by checking the exit codes of commands and taking
appropriate actions. The `%ERRORLEVEL%` variable is often used to check whether a command
executed successfully or encountered an error.
Environment Interaction
Batch scripts can interact with and modify environment variables to affect the system's
behavior temporarily or permanently.
Overall, the objectives of commands in batch scripts are to provide a means to automate tasks,
process data, and control the sequence of operations, making them a powerful tool for Windows
system administration and automation.
Usage:
When you run the `VER` command in the Command Prompt or a batch
script, it will output the version information of the Command Prompt.
Example:
2. ASSOC
This is a batch command that associates an extension with a file type (FTYPE), displays
existing associations, or deletes an association. The `ASSOC` command in Windows
Command Prompt (CMD) is used to display or modify file extension associations. It shows
the relationship between file extensions and their corresponding file types registered in the
Windows registry. When you open a file with a specific extension, Windows uses the
association to determine which program should be used to open that file.
Syntax:
Usage:
- To display the current file extension associations, run the `ASSOC`
command without any additional arguments.
- To display the file type associated with a specific file extension, provide the
extension as an argument (e.g., `ASSOC .txt` will show the association
for .txt files).
- To set or change the association between a file extension and a file type,
use the `ASSOC` command in combination with the `FTYPE` command.
Example:
3. CD
4. CLS
5. COPY
6. DEL Sir madi mi pay nalpas dituy nga
7. DIR
part
8. DATE
9. ECHO
10. EXIT
11. MD
12. MOVE
13. PATH
14. PAUSE
15. PROMPT
The cmd.exe prompt can be changed or reset with this batch command.
DISCUSSION
The "prompt" command is used in the context of the Windows Command Prompt (CMD) to
change the appearance of the command prompt itself. It lets you customize the prompt text to display
information like the current directory, time, date, or other custom text, making it easy to recognize the
context of your current session.
EXAMPLE
OUTPUT
16. RD
This batch command deletes folders, but they must be empty before they may be deleted.
DISCUSSION
In the Windows Command Prompt (cmd), the "rd" command stands for "remove directory,"
and it is used to delete directories (folders) on your computer. When using this command, use caution
because removing directories is irrevocable, and the data contained within those folders is
permanently gone. Before running the command, make sure you have sufficient backups and double-
check the directory you wish to remove.
EXAMPLE
OUTPUT
17. REN
Files and folders are renamed.
DISCUSSION
The ren command in the Windows command-line environment (CMD) is used to rename files
or directories (folders). The word "ren" means "rename."
EXAMPLE
OUTPUT
18. REM
This batch command is used for notes in batch files to prohibit the remark's content from
being executed.
DISCUSSION
The rem command in Windows Command Prompt (CMD) is used to insert comments into
batch or command-line programs. A remark is a line of text that is not performed as part of the script
and is intended for human readers to add notes, explanations, or instructions. The rem command
allows you to add comments to a script without impacting its execution.
EXAMPLE
OUTPUT
19. START
This batch command launches an application or opens a document in a new window.
DISCUSSION
The start command in the Windows operating system is used to launch applications, open
files, or execute commands from the Command Prompt (cmd) or batch scripts. It lets you start
numerous tasks without having to wait for the command to finish, and it can open files with their
default programs.
EXAMPLE
OUTPUT
20. TIME
The time is set or shown with this batch command.
DISCUSSION
The "time" command in Windows operating systems is used to show or set the current system
time. To perform different time-related activities, the "time" command is issued in the Command
Prompt (cmd.exe).
EXAMPLE
OUTPUT
21. TYPE
This batch command outputs the contents of a file or files.
DISCUSSION
In the Windows Command Prompt (cmd), the type command is used to display the contents
of a text file directly in the command window. It is an easy tool that can be useful for rapidly seeing
the contents of a file without opening it in a text editor.
EXAMPLE
OUTPUT
22. VOL
The volume labels are displayed by this batch command.
DISCUSSION
There is no explicit "vol" command in Windows Command Prompt (cmd) that performs any
volume-related activities as of my last update in September 2021. However, additional commands or
upgrades may have been implemented since then. Please bear in mind that my information may be out
of current, and I recommend consulting the Windows manual or performing the "vol /?" command in
cmd to obtain the most recent information.
EXAMPLE
OUTPUT
23. ATTRIB
The attributes of the files in the current directory are displayed or set.
DISCUSSION
In the Windows Command Prompt, use the "attrib" command to show or change the
characteristics of files and folders. This command is useful for managing file permissions and
properties.
EXAMPLE
OUTPUT
24. CHKDSK
This batch command scans the disk for errors.
DISCUSSION
chkdsk (short for "Check Disk") is a command-line utility in Windows operating systems that
checks the file system and storage media (e.g., hard disk drives and solid-state drives) for integrity. It
searches the disk for defects, bad sectors, and other problems before attempting to repair them. The
chkdsk command is executed using the Command Prompt (cmd.exe).
EXAMPLE
OUTPUT
25. CHOICE
The user is given a list of options using this batch command.
DISCUSSION
The "choice" command is a command-line utility in Windows Command Prompt (cmd) that
allows users to prompt for user input and wait for a keypress before continuing execution. This
command is very useful for adding interactivity and making decisions based on user input in batch
scripts or batch files.
EXAMPLE
OUTPUT
26. CMD
This batch command launches another command prompt.
DISCUSSION
CMD (Command Prompt) is a command-line interpreter application that allows users to
communicate with the system using text commands in the context of Microsoft Windows operating
systems. It allows you to run numerous activities, manage files and folders, change system settings,
and more. Power users, system administrators, and developers frequently employ CMD commands
for a variety of objectives.
EXAMPLE
OUTPUT
27. COMP
This batch function compares the sizes of two files.
DISCUSSION
The comp command is used in the Windows command prompt (cmd) to compare the contents
of two files or groupings of files. It determines whether the files are identical or not.
EXAMPLE
OUTPUT
28. CONVERT
This batch command transforms a volume's file system from FAT16 or FAT32 to NTFS.
DISCUSSION
The "convert" command in Windows is used to convert the file system of a volume from one
type to another. The most common use case is to convert a FAT (File Allocation Table) file system
without losing data to an NTFS (New Technology File System) file system. The command "convert"
is available in the Command Prompt (cmd).
EXAMPLE
OUTPUT
29. DRIVERQUERY
This batch command displays the properties of all installed device drivers.
DISCUSSION
The driverquery command is available in Windows Command Prompt (cmd) and PowerShell.
It provides users with access to a list of all device drivers installed on the Windows operating system.
This command can be used to verify driver information such as driver names, descriptions, version
numbers, and dates.
EXAMPLE
OUTPUT
30. EXPAND
This batch command removes files from.cab cabinet files that have been compressed.
DISCUSSION
The "expand" command is a command-line program in Windows that is used to extract files
from a Microsoft Cabinet (CAB) file. CAB files are compressed archives that Microsoft typically
uses for software distribution and installation packages. The "expand" command is most commonly
used to extract the contents of CAB files.
EXAMPLE
OUTPUT
31. FIND
This batch program searches files or input for a string and outputs matching lines.
DISCUSSION
CMD (Command Prompt)'s find command is used to look for specified text patterns within
files. It is analogous to the Unix/Linux grep command. The locate function is useful for quickly
discovering lines of text in a file or set of files that contain specified keywords or phrases.
EXAMPLE
OUTPUT
32. FORMAT
This batch program reformat a drive to use a Windows-supported file system like FAT,
FAT32, or NTFS, overwriting the disk's prior content.
DISCUSSION
The format command in the Windows command-line interface (CMD) is used to format a
storage device, often a disk drive such as a hard disk or a USB flash drive. Formatting a disk removes
all data from the device and prepares it for new data storage. If not used correctly, the command can
be harmful because it can permanently destroy all data on the specified device.
EXAMPLE
format [/FS:file-system] [/V:volume-label] [/Q] [/A:size] [/C] [/X] drive:
OUTPUT
33. HELP
This batch command displays a list of commands provided by Windows.
DISCUSSION
The "help" command is a built-in command in Windows Command Prompt (cmd) that
displays information about other commands accessible in the Command Prompt environment. When
you run the "help" command, it displays a list of commands and their brief descriptions, allowing you
to easily identify and learn about the command you need.
EXAMPLE
OUTPUT
34. IPCONFIG
This batch command displays the IP configuration of Windows. Displays configuration by
connection as well as the name of the connection.
DISCUSSION
The ipconfig (Internet Protocol Configuration) command, which is accessible in Windows
Command Prompt (CMD) and Windows PowerShell, is a helpful utility. It enables Windows users to
monitor and manage network-related information. The command displays IP configuration
information such as IP addresses, subnet masks, default gateways, DNS servers, and more. It is
especially useful for debugging network connectivity problems.
EXAMPLE
OUTPUT
35. LABEL
This batch command adds, modifies, or deletes a disk label.
DISCUSSION
The "label" command in Windows Command Prompt (cmd) is used to create, change, or
remove a volume label on a disk drive. A volume label is a name given to a disk drive or partition that
allows users to easily identify and distinguish between different storage devices. This label appears
when examining the drive in File Explorer or running specific commands in the Command Prompt.
EXAMPLE
OUTPUT
36. MORE
The contents of a file or files are displayed one screen at a time using this batch operation.
DISCUSSION
The more command in Windows Command Prompt (cmd) is a basic command-line utility
that allows users to examine text files one screen at a time. It is used to read through long text output
or to paginate the content of text files. When working with big files that might normally scroll off the
screen too quickly, the more command comes in handy.
EXAMPLE
OUTPUT
37. NET
Depending on the instruction, provides a variety of network functions.
DISCUSSION
The net command in Windows Command Prompt (cmd) is a command-line program that
allows you to control different network-related tasks and services. It enables interaction with network
resources such as user accounts, shared directories, and network setups.
EXAMPLE
OUTPUT
38. PING
This batch command transmits ICMP/IP "echo" packets to the specified address via the
network.
DISCUSSION
The ping command is a popular networking tool that may be found in the Windows
Command Prompt (CMD) and other command-line interfaces. It is used on a TCP/IP network to
evaluate the connectivity and response time of a network host or IP address (either a website, server,
or any other device). The ping command delivers tiny data packets to the target host and measures the
time it takes for the packets to travel to the target and back.
EXAMPLE
OUTPUT
39. SHUTDOWN
This batch command either shuts down the computer or logs the current user out.
DISCUSSION
To shut down, restart, or log off a Windows operating system, use the "shutdown" command
in Command Prompt (cmd). It gives you command-line access to the system's power management
options. The command has several arguments that allow you to tailor the shutdown behavior to your
own requirements.
EXAMPLE
OUTPUT
40. SORT
This batch command arranges the contents of a source file alphabetically, from A to Z or Z to
A. The output is printed to the console.
DISCUSSION
The sort command in Windows Command Prompt (cmd) is a valuable function that allows
you to sort the contents of a text file or the output of another command. It arranges the lines
alphabetically, numerically, or depending on the criteria you specify.
EXAMPLE
OUTPUT
41. SUBST
This batch command assigns a drive letter to a local folder, displays current assignments, and
removes a drive letter.
DISCUSSION
The subst command is used in the Windows command prompt (cmd) to establish a virtual
drive letter that points to a certain directory on your computer's file system. This virtual drive
functions similarly to a regular drive letter (for example, C:, D:), allowing you to go to it and retrieve
its contents using ordinary file management commands.
EXAMPLE
OUTPUT
42. SYSTEMINFO
This batch command displays a computer's and operating system's setup.
DISCUSSION
The systeminfo command is a built-in command in the Windows Command Prompt (cmd)
that displays a detailed overview of various system data. The systeminfo command collects data from
the computer's hardware and operating system and shows detailed information about the system's
settings. This information is useful for troubleshooting, system administration, and general system
comprehension.
EXAMPLE
OUTPUT
43. TASKKILL
This batch command will terminate one or more tasks.
DISCUSSION
The taskkill command in Windows is a powerful command-line tool that allows you to
terminate or forcefully end processes (applications or tasks) that are operating on your computer. It is
very handy when dealing with sluggish or hung applications that must be forced closed. Windows
Command Prompt (cmd) and Windows PowerShell both support the taskkill command.
EXAMPLE
OUTPUT
44. TASKLIST
This batch command displays a list of tasks, together with the task name and process id
(PID).
DISCUSSION
The tasklist command is a powerful tool in Windows Command Prompt (cmd) that displays a
list of all the processes that are currently operating on your computer. It displays precise information
about each process, such as the process ID (PID), session name, session number, memory use, and
other details.
EXAMPLE
OUTPUT
45. XCOPY
This batch command does more advanced file and directory copying.
DISCUSSION
xcopy is a command-line program in Windows Command Prompt (CMD) that allows you to
copy files and directories with more capability than the simple copy command. "xcopy" is an
abbreviation for "extended copy."
EXAMPLE
OUTPUT
46. TREE
This batch tool displays a tree of all subdirectories of the current directory at any level of
recursion or depth.
DISCUSSION
The "tree" command in Windows Command Prompt (cmd) is a simple and handy program
that displays the directory structure of a specified folder and its subfolders as a tree-like
representation. It provides a fast overview of the folder hierarchy, making it easy to comprehend how
files and directories are organized within a certain route.
EXAMPLE
OUTPUT
47. FC
This batch command compares the differences between two files.
DISCUSSION
There is an external program named fc.exe, which stands for "File Compare," and it is used in
Windows to compare the contents of two text or binary files. In the Windows PowerShell
environment, the fc command is also available.
EXAMPLE
OUTPUT
48. DISKPART
This batch command displays and configures disk partition properties.
DISCUSSION
Diskpart is a command-line application included with Windows that allows users to manage
disks, partitions, and volumes. It includes a comprehensive collection of commands for doing disk-
related tasks including as creating, deleting, resizing, and formatting partitions, as well as establishing
active partitions and assigning drive letters. Diskpart may be quite handy for efficiently managing
disk storage. Please keep in mind that some procedures may result in data loss, so use this tool with
caution.
EXAMPLE
OUTPUT
49. TITLE
This batch command changes the title of the console window.
DISCUSSION
The "title" command in Windows Command Prompt (cmd) is used to change the title of the
Command Prompt window. The title shows in the window's title bar and assists users in
distinguishing between multiple Command Prompt sessions or determining the purpose of the current
window.
EXAMPLE
OUTPUT
50. SET
Displays a list of the current system's environment variables.
DISCUSSION
The "set" command in Windows command prompt (cmd) is used to create, change, or display
environment variables. Environment variables are a collection of dynamic parameters that can
influence the behavior of various processes and apps on the Windows operating system. They save
data like system paths, user preferences, and other configuration settings.
EXAMPLE
OUTPUT