💻 Command Line & Terminal Basics

Command Line & Terminal Basics

Master the primary interface for IT professionals. Learn to navigate filesystems, manipulate files, and automate tasks using Windows CMD and PowerShell.

🕐 ~2.5 Hours 💻 CLI Practice CompTIA A+ 220-1102 Core Skill

Learning Objectives

Module 1: CMD Fundamentals

~30 min

Navigation & View

The Command Prompt (CMD) is the legacy Windows shell. While older, it's still widely used for simple tasks and legacy scripts.

C:\Users\Student> dir
C:\Users\Student> cd Documents
C:\Users\Student\Documents> cls
C:\Users\Student\Documents> cd ..
  • dir: List files and directories in current location
  • cd (Change Directory): Move between folders
  • cls: Clear the screen
  • chdir: Display the name of the current directory

Content & Management

Viewing and managing files directly without a GUI.

C:\> echo Hello IT Support > test.txt
C:\> type test.txt
C:\> copy test.txt backup.txt
C:\> move backup.txt C:\Temp\
C:\> del test.txt
  • echo: Output text or create files
  • type: Display the contents of a text file
  • copy / move: File operations
  • del: Delete files
  • tree: Graphical display of folder structure

Real-World Scenario

A user needs a list of every file in a specific folder including subfolders. You can't manually copy-paste names. Use dir /s > filelist.txt to export the entire structure to a text file for them.

Module 2: PowerShell Basics

~45 min

Verb-Noun Syntax

PowerShell is built on .NET and uses a predictable Verb-Noun naming convention for cmdlets.

PS C:\> Get-ChildItem
PS C:\> Set-Location -Path "C:\Windows"
PS C:\Windows> Get-Command *Service*
  • Get-ChildItem (gci): The PS equivalent of dir
  • Set-Location (cd): Change directories
  • Get-Help: Your best friend for learning flags and syntax

Piping & Objects

In CMD, pipes pass text. In PowerShell, pipes pass **Objects**. This allows for powerful filtering.

PS C:\> Get-Service | Where-Object {$_.Status -eq "Running"}
PS C:\> Get-Process | Sort-Object CPU -Descending | Select-Object -First 5
  • Get-Service: List all Windows services
  • Get-Process: List running applications
  • Start-Process / Stop-Process: Control applications
  • Variables: Declared with $ (e.g., $myVar = "Data")

Hands-On Lab: Process Hunter

  1. Open PowerShell as Administrator.
  2. Run Get-Process | Select-Object Name, CPU, WorkingSet | Sort-Object CPU -Descending | Select-Object -First 10.
  3. Identify the process using the most memory (WorkingSet).
  4. Open Notepad, then use Get-Process notepad | Stop-Process to kill it.

Module 3: Navigating Filesystems

~20 min

Paths: Absolute vs Relative

Understanding where you are and how to point to other locations is critical.

  • Absolute Path: The full address from the root (e.g., C:\Users\Admin\Desktop\notes.txt)
  • Relative Path: Relative to where you are now (e.g., ..\Documents\report.pdf)
  • The Dot: . refers to current directory, .. refers to parent directory

Windows vs Linux Navigation

While similar, notice the slash direction and drive letters.

Feature Windows (CMD/PS) Linux (Bash)
Root C:\ /
Slash Backslash (\) Forward Slash (/)
Home %USERPROFILE% ~
List Files dir ls

Module 4: File Operations Deep Dive

~30 min

Wildcards: The Asterisk and Question Mark

Manipulate groups of files with ease.

  • *: Matches any number of characters (del *.tmp)
  • ?: Matches exactly one character (copy image??.jpg folder/)

Redirection Symbols

  • >: Overwrite file with output (ipconfig > network.txt)
  • >>: Append output to end of file (date >> log.txt)
  • |: Pipe - Send output of one command as input to another

Checkpoint

What command would you use to list all files ending in .log and save that list to a file named audit.txt without deleting what's already in audit.txt?

View Answer

dir *.log >> audit.txt (or Get-ChildItem *.log >> audit.txt in PowerShell)

Module 5: Shell Environments

~20 min

Comparing Shells

  • CMD: Fast, lightweight, limited logic. Best for quick troubleshooting on older systems.
  • PowerShell: Extremely powerful, handles objects, scriptable. The standard for Windows Administration.
  • Bash: The standard for Linux and macOS. Now available on Windows via WSL (Windows Subsystem for Linux).

When to use which?

If you need to restart a service on 100 remote Windows machines, use PowerShell (Invoke-Command). If you need to check if a local file exists in a simple batch file, CMD is fine. If you are managing a web server running Ubuntu, use Bash.

Hands-on Labs: Practical Exercises

Exercise 1: Filesystem Scavenger Hunt

  1. Create a folder named Lab_Foundation on your desktop.
  2. Inside, create three folders: Docs, Logs, Backup.
  3. Create a file in Docs named info.txt containing your name.
  4. Move info.txt to Backup using only the command line.

Exercise 2: System Audit

  1. Open CMD and export your network configuration to network_info.txt.
  2. Append your system's hostname to that same file.
  3. Use type to verify the content.

Exercise 3: PowerShell Management

  1. Use PowerShell to find all services that are currently "Stopped".
  2. Export that list to a CSV file using Export-Csv.

Commands Quick Reference

Action CMD PowerShell
List Files dir Get-ChildItem
Copy File copy Copy-Item
Move File move Move-Item
Delete File del Remove-Item
Make Directory mkdir New-Item -ItemType Directory
Network Config ipconfig Get-NetIPAddress

Knowledge Check

Q1: What does the command 'cd ..' do?

It moves the current terminal session up one level to the parent directory.

Q2: What is the difference between '>' and '>>'?

'>' overwrites the destination file with new output, while '>>' appends the output to the end of the existing file.

Q3: Which shell environment is considered "Object-Oriented"?

PowerShell. It passes structured objects through the pipeline rather than just plain text strings.

Q4: How do you search for help on a command in PowerShell?

Use the Get-Help cmdlet followed by the command name (e.g., Get-Help Get-Service).

Resources & Further Reading

Official PowerShell Documentation SS64: Command Line Reference (Excellent resource!) Bash Cheat Sheet
Progress: 0%