Exercise 1 - Basic Commands:
Linux -> Windows
ls -> dir (List files and directories)
cd -> cd (Change directory - same in both)
pwd -> cd (Print working directory - just 'cd' without arguments shows current path)
mkdir -> mkdir/md (Create directory)
rmdir -> rmdir/rd (Remove directory)
cp -> copy (Copy files)
mv -> move (Move/rename files)
rm -> del (Delete files)
more -> more (Display file content page by page)
==================================================
Exercise 2 - File Handling:
Linux -> Windows
touch -> (Create empty file) , type nul.> filename
chmod -> icacls (Change file permissions)
chown -> takeown (Change file ownership)
ln -> mklink (Create links)
find -> find/findstr (Search for files/text)
locate -> where (Find file locations)
grep -> findstr (Search text patterns)
===============================================
Exercise 3 - Process Management:
Linux -> Windows
ps -> tasklist (List processes)
top -> taskmgr (Task manager - GUI)
kill -> taskkill (Terminate processes)
nice -> start /priority (Set process priority)
================================
Exercise 4 - Disk Utilities:
Linux -> Windows
df -> wmic logicaldisk get size,freespace,caption
du -> dir /s (Show directory sizes)
mount -> mountvol (Mount volumes)
fsck -> chkdsk (Check disk)
mkfs -> format (Format disk)
==========================
Exercise 5 - Networking:
Linux -> Windows
ping -> ping (Test network connectivity)
ifconfig -> ipconfig (Show network configuration)
netstat -> netstat (Network statistics)
traceroute -> tracert (Trace network route)
ssh -> ssh (Windows 10+ has OpenSSH)
scp -> xcopy/robocopy (Copy files over network)
ftp -> ftp (File transfer protocol)
wget -> curl (Download files - Windows 10+)
============================================
Exercise 6 - Text Processing:
sort (Sort text)
=============================================
Exercise 7 - Backup:
Linux -> Windows
gzip -> compact (Windows built-in compression)
zip -> compact or powershell Compress-Archive
unzip -> compact or powershell Expand-Archive
rsync -> robocopy (Robust file copy)
==============================
Exercise 8 - Text Editor Commands:
Linux (vi) -> Windows (notepad)
vi filename -> notepad filename (Open file)
i (insert) -> Just start typing (Insert text)
:wq -> Ctrl+S, Alt+F4 (Save and quit)
:q! -> Alt+F4 (Quit without saving)
dd -> Delete/Backspace (Delete text)
==============================
Exercise 9 - Basic Scripting (Batch Files):
Linux (.sh) -> Windows (.bat or .cmd)
# Variables
Linux -> Windows
var="value" -> set var=value
$var -> %var%
# Loops
Linux -> Windows
for loop:
for i in 1 2 3 -> for %%i in (1 2 3) do (
do echo %%i
echo $i )
done
while loop:
while condition -> :while
do if condition (
commands commands
done goto while
# Conditionals
Linux -> Windows
if [ condition ] -> if condition (
then commands
commands )
fi else (
commands
===================================
Exercise 10 - Redirection:
Linux -> Windows
| -> | (Pipe - same in both)
> -> > (Redirect output - same in both)
>> -> >> (Append output - same in both)
< -> < (Input redirection - same in both)
=====================================
Exercise 11 - Wildcards:
Linux -> Windows
* -> * (Wildcard - matches any characters)
? -> ? (Single character wildcard)
========================================
Exercise 12 - Debugging Batch Scripts:
Linux -> Windows
set -x -> echo on (Show commands as they execute)
set +x -> echo off (Hide commands)
trap -> No direct equivalent, but can use:
- errorlevel (Check error status)
- goto :error (Error handling)
Example debugging in Windows batch:
```bat
@echo on
REM This will show each command as it executes
set var=value
echo %var%
@echo off
Error handling example:
@echo off
somecommand.exe
if errorlevel 1 (
echo An error occurred
goto :error
:error
echo Error handling routine here
pause
=================
Common batch script debugging techniques:
1. Use echo statements to print variable values:
echo Current value is: %variable%
2. Use pause to halt execution:
echo Debugging checkpoint
pause
3. Check if files/folders exist:
if exist "filename" (
echo File found
) else (
echo File not found
4.Display all variables:
Set
5. Enable command echoing for specific sections:
@echo off
echo Starting...
@echo on
REM Debug this section
command1
command2
@echo off
echo Done.
Ques: How to create user registration details like, username,
name,age,gender,etc.with the help of commands?
Step 1: Create a Batch Script
1. Open Notepad or any text editor.
2. Write the following batch script:
set /p username="Enter your username: "
set /p password="Enter your password: "
set /p name="Enter your name: "
set /p age="Enter your age: "
set /p gender="Enter your gender (M/F): "
: Display the collected information
echo.
echo Registration Details:
echo ---------------------
echo Username: %username%
echo Password: %password%
echo Name: %name%
echo Age: %age%
echo Gender: %gender%
:: Save the output to a file
echo Registration Details: > registration.txt
echo --------------------- >> registration.txt
echo Username: %username% >> registration.txt
echo Password: %password% >> registration.txt
echo Name: %name% >> registration.txt
echo Age: %age% >> registration.txt
echo Gender: %gender% >> registration.txt
echo.
echo Your registration details have been saved to registration.txt
pause
Step 2: Save the Batch Script
1. Save the file with a .bat extension, for example, registration.bat.
2. Make sure to select "All Files" in the "Save as type" dropdown in
Notepad to avoid saving it as a .txt file.
Step 3: Run the Batch Script
1. Open the Command Prompt (cmd).
2. Navigate to the directory where you saved the registration.bat file.
3. Run the script by typing registration.bat and pressing Enter.
Step 4: Input User Details
1. The script will prompt you to enter your username, password, name,
age, and gender.
2. After entering the details, the script will display the collected
information on the screen and save it to a file named registration.txt.
Explanation of the Script
● @echo off: Prevents the commands from being displayed in the
command prompt.
● cls: Clears the screen.
● set /p variable="prompt": Prompts the user to input a value and
assigns it to a variable.
● echo.: Prints a blank line.
● >> registration.txt: Appends the output to the registration.txt file.
● pause: Pauses the script and waits for the user to press a key before
closing the command prompt.
Output
The script will output the collected information both on the screen and in a
file named registration.txt. The file will contain the following:
Registration Details:
---------------------
Username: [user input]
Password: [user input]
Name: [user input]
Age: [user input]
Gender: [user input]