BCA101 Computer Fundamentals and Applications

Computer Fundamentals and ApplicationsUnit 414 min read

DOS & CLI: Commands, File Systems, Batch Scripts & Troubleshooting

Unit 4 of Computer Fundamentals and Applications covers DOS (Disk Operating System) architecture, essential commands, file management, batch scripting, and command-line interface (CLI) operations—critical for system administration, automation, and troubleshooting in real-world IT environments.

TAKEAWAYS:

  • DOS commands are categorized into file management, disk operations, networking, and system utilities, each with specific syntax and flags.
  • The command-line interface (CLI) offers precise control over files, directories, and system processes, unlike GUI limitations.
  • Batch scripting automates repetitive tasks using .bat files, combining commands with conditional logic (IF, FOR).
  • Error handling in DOS relies on exit codes, redirection (>, >>, |), and logical operators (&&, ||).
  • Modern CLI tools (e.g., PowerShell, Bash) extend DOS concepts with scripting, pipelines, and advanced text processing.
  • Real-world applications include system administration (e.g., NTC network diagnostics), automation (e.g., Daraz inventory updates), and legacy system maintenance.

1. Introduction to DOS and CLI

What is DOS?

DOS (Disk Operating System) is a non-graphical command-line interface for managing computer hardware and software. Developed by Microsoft (MS-DOS) and IBM (PC-DOS), it remains foundational for understanding:

  • File systems (FAT16, FAT32, NTFS).
  • System commands (e.g., DIR, COPY).
  • Batch processing (automating tasks via scripts).

Why learn DOS?

  • Legacy systems: Many industrial/embedded systems still use DOS.
  • Networking tools: Commands like PING, TRACERT (from DOS roots) are used in NTC/Ncell diagnostics.
  • Scripting: Batch files automate backups, log parsing, and system maintenance.

CLI vs. GUI: Key Differences

Feature Command-Line Interface (CLI) Graphical User Interface (GUI)
Input Method Text commands (e.g., DEL file.txt) Mouse/keyboard clicks (icons, menus)
Precision Exact syntax required Forgiving (e.g., drag-and-drop)
Speed Faster for repetitive tasks Slower for complex operations
Access Requires knowledge of commands User-friendly for beginners
Use Cases Server administration, scripting General user tasks (word processing)

2. DOS File System and Directory Structure

How Files and Directories Work

  • Root directory: The top-level folder (e.g., C:\).
  • Subdirectories: Folders within folders (e.g., C:\Users\Documents).
  • File paths: Specify location using backslashes (\). Example: C:\Data\Reports\Q1_Sales.txt.

Worked Example: Creating a Directory Structure Task: Replicate this structure using DOS commands:

E:\ROOT
├── dir_1/
│   ├── file_1.txt
│   └── file_2.txt
├── dir_2/
│   └── dir_3/
│       └── file_2.txt
└── dir_2.txt

Solution:

E:
MD ROOT
CD ROOT
MD dir_1
MD dir_2
CD dir_1
COPY CON file_1.txt
[Type text, press F6 then Enter to save]
COPY CON file_2.txt
[Type text, press F6 then Enter]
CD ..\dir_2
MD dir_3
CD dir_3
COPY CON file_2.txt
[Save file]
CD ..\..
COPY CON dir_2.txt
[Save file]

File Naming Rules

Rule Example
Max 255 chars Project_2024_Report.doc
No `:*?<> `
Case-insensitive FILE.TXT = file.txt
Extensions .txt, .bat, .exe

3. Essential DOS Commands

11111DIRCOPYDELRENMDCDRD
Common DOS command relationships (usage patterns)

Categorized Command List

Category Command Example Purpose
File Operations COPY COPY file1.txt C:\Backup\ Copies files/directories.
DEL/ERASE DEL old_file.txt Deletes a file.
REN REN old.txt new.txt Renames a file.
Directory MD/MKDIR MD C:\Projects Creates a directory.
RD/RMDIR RD C:\Temp Deletes a directory (must be empty).
CD/CHDIR CD C:\Users Changes directory.
Display DIR DIR /P Lists files (with pagination).
TYPE TYPE readme.txt Displays file content.
Disk FORMAT FORMAT D: Formats a disk (destructive!).
DISKCOPY DISKCOPY A: B: Copies disk contents.
System DATE/TIME TIME 14:30 Sets system date/time.
CLS CLS Clears the screen.
Networking PING PING google.com Tests network connectivity.
TRACERT TRACERT ncell.com Traces route to a host.
Batch ECHO ECHO Hello > greeting.txt Displays messages or writes to files.
PAUSE PAUSE Halts script execution.

Worked Example: Bank Transaction Log Analysis

Scenario: A bank (e.g., Nabil Bank) uses DOS batch scripts to log daily transactions. Write a script to:

  1. Create a log file transactions.log.
  2. Append today’s date and a sample transaction.
  3. Display the log.

Solution:

@ECHO OFF
ECHO Today's Transactions - %DATE% > transactions.log
ECHO Account: 123456789, Amount: NPR 50,000, Type: Deposit >> transactions.log
ECHO Account: 987654321, Amount: NPR 20,000, Type: Withdrawal >> transactions.log
TYPE transactions.log
PAUSE

Output:

Today's Transactions - 05/10/2024
Account: 123456789, Amount: NPR 50,000, Type: Deposit
Account: 987654321, Amount: NPR 20,000, Type: Withdrawal

4. Advanced DOS Features

Redirection and Piping

  • Redirection (>): Overwrites a file with command output.
    DIR > filelist.txt
    
  • Append (>>): Adds output to a file without overwriting.
    ECHO New line >> filelist.txt
    
  • Piping (|): Sends output of one command to another.
    DIR | FIND "txt"
    
    Example: List only .txt files in the current directory.
Commanddir *.txtRedirection>Outputoutput.txt
How redirection works (command → file)

Batch Scripting Basics

Batch files (.bat) automate tasks using:

  • Variables: %VAR% (e.g., %DATE%).
  • Conditionals: IF statements.
  • Loops: FOR loops.

Example: Backup Script

@ECHO OFF
SET BACKUP_DIR=C:\Backup\%DATE%
MKDIR %BACKUP_DIR%
COPY C:\Data\*.* %BACKUP_DIR%\ /Y
ECHO Backup completed at %TIME% >> %BACKUP_DIR%\backup_log.txt

Use Case: Daraz might use similar scripts to auto-backup inventory data nightly.


Error Handling

  • Exit Codes: 0 = Success, 1 = Error.
    IF ERRORLEVEL 1 ECHO Command failed!
    
  • Logical Operators: && (AND), || (OR).
    DIR && ECHO Success || ECHO Failed
    

5. DOS in Real-World Applications

In the Real World

  1. NTC Network Diagnostics:

    • Tool: PING, TRACERT, IPCONFIG.
    • How: Technicians use these to troubleshoot internet outages in Kathmandu traffic routes (e.g., Thapathali to Balaju).
    • Example:
      PING 8.8.8.8
      TRACERT ntc.net.np
      
  2. Khalti Payment Gateway:

    • Tool: Batch scripts for transaction logs.
    • How: Khalti’s backend systems use DOS-like scripts to generate daily reports of successful/failed transactions.
    • Example Script:
      ECHO Transaction Report - %DATE% > khalti_log.txt
      FOR /F "tokens=1-3" %%A IN (transactions.csv) DO (
        ECHO %%A, %%B, %%C >> khalti_log.txt
      )
      
  3. Pathao Driver Dispatch:

    • Tool: SORT and FIND commands.
    • How: Pathao’s legacy systems (for older drivers) use DOS commands to sort ride requests by proximity.
    • Example:
      TYPE ride_requests.txt | FIND "status=pending" | SORT > pending_requests.txt
      
  4. NEPSE Stock Data Processing:

    • Tool: TYPE + FINDSTR.
    • How: Analysts extract specific stock prices from daily logs.
    • Example:
      TYPE stock_data.txt | FINDSTR "NEPSE:5000" > top_gainers.txt
      

Worked Example: Daraz Order Queue Simulation

Scenario: Daraz uses a first-in-first-out (FIFO) queue for order processing. Simulate this with DOS commands.

Steps:

  1. Create an order log:
    ECHO Order1,User123,Pending > orders.txt
    ECHO Order2,User456,Pending >> orders.txt
    ECHO Order3,User789,Pending >> orders.txt
    
  2. Process orders in order (FIFO):
    @ECHO OFF
    SET /P order=<orders.txt
    ECHO Processing: %order%
    SHIFT
    FOR %%G IN (%*) DO (
      ECHO Next order: %%G
      TIMEOUT /T 2 > NUL
    )
    

Output:

Processing: Order1,User123,Pending
Next order: Order2,User456,Pending
Next order: Order3,User789,Pending

6. DOS vs. Modern CLI Tools

Feature DOS PowerShell (Windows) Bash (Linux/macOS)
Scripting .bat files .ps1 files (PowerShell) .sh files (Bash)
Piping Limited (` `) Advanced (Select-Object, Where)
Variables %VAR% $VAR $VAR or VAR
Conditionals IF if () {} if [ condition ]; then fi
Use Case Legacy systems, embedded devices Enterprise automation Linux servers, DevOps

7. Common Pitfalls and Troubleshooting

Common Errors and Fixes

Error Cause Solution
'command' is not recognized Command not in PATH or typo. Check spelling or use full path (e.g., C:\DOS\COPY).
Access denied Permission issues. Use ATTRIB -R file.txt to remove read-only.
File not found Incorrect path. Verify path with DIR /S.
Invalid switch Wrong flag (e.g., /P vs. /PAGE). Check HELP command or command /?.

Example Trace: Problem: COPY file.txt C:\Backup\ fails with "Access denied." Trace:

  1. Check permissions: ATTRIB file.txt → Shows "R" (read-only).
  2. Fix: ATTRIB -R file.txt.
  3. Retry: COPY file.txt C:\Backup\ → Success.

Hidden DOS Commands

Command Purpose
MEM Displays memory usage.
VER Shows DOS version.
PROMPT Customizes command prompt (e.g., PROMPT $P$G).
HELP or ? Lists commands or describes a command.

Exam Tip

How to Score Full Marks

  1. Command Syntax:

    • Always include flags (e.g., DIR /P not just DIR).
    • Use full paths in examples (e.g., C:\Users\file.txt).
  2. Batch Scripts:

    • Structure answers with:
      • @ECHO OFF (to hide commands).
      • Clear comments (REM This copies files).
      • Error handling (IF ERRORLEVEL).
  3. Real-World Applications:

    • Link commands to Nepali contexts (e.g., NTC, Khalti, Daraz).
    • Example: For PING, mention "diagnosing slow internet in Pokhara."
  4. Diagrams:

    • Draw directory trees for file structure questions.
    • Use sequence diagrams for protocol-like operations (e.g., batch script flow).
  5. Common Exam Questions:

    • Create a directory structure: Use MD + CD commands.
    • Batch script for calculations: Use SET /A for math (e.g., SET /A sum=5+3).
    • Networking commands: Always include PING and IPCONFIG.

Example Answer Structure: Question: Write DOS commands to create the following structure:

C:\Data
├── Reports\
│   ├── Q1.txt
│   └── Q2.txt
└── Backup\
    └── old_files\

Answer:

MD C:\Data
CD C:\Data
MD Reports
MD Backup\old_files
CD Reports
COPY CON Q1.txt
[Press F6, Enter]
COPY CON Q2.txt
[Press F6, Enter]

Visual:

Q1.txtQ2.txtReportsold_filesBackupDataC:\
Directory structure for COPY CON Q2.txt command (Q2.txt created in Reports folder)

Past Exam Patterns

  • Short Answer: Define COPY command + example (2 marks).
  • Long Answer: Write a batch script to:
    • Backup files (3 marks).
    • Calculate statistics (e.g., sum of numbers in a file) (5 marks).
  • Scenario-Based: "A company uses DOS to log sales. Write commands to filter sales > NPR 10,000" (4 marks).

Pro Tips

  • Memorize flags: /P, /S, /A (for DIR, COPY, ATTRIB).
  • Practice typing: DOS is case-insensitive but flags are exact (e.g., /PAGE ≠ /page).
  • Use HELP: In DOS, type HELP or command /? to see examples.

Based on the TU BCA syllabus for Computer Fundamentals and Applications (BCA101), unit 4.

Discussion

Loading…