Command Line Interfaces
The command line is one of the most powerful tools for system administrators. While graphical interfaces make many tasks easier, the command line provides:- More direct system communication
- Better automation capabilities
- Access to all system features
- Scriptability for repetitive tasks
PowerShell (Windows)
PowerShell has become the default interpreter in Windows 10 (since November 2017), replacing CMD as the primary administrative tool.Why PowerShell?
Object-Oriented
Everything is an object, not text strings, providing richer data manipulation
.NET Integration
Full access to .NET Framework capabilities
Cross-Platform
PowerShell Core runs on Windows, Linux, and macOS
Consistent Syntax
Verb-Noun naming convention makes commands predictable
cmdlet Structure
All PowerShell cmdlets follow theVerb-Noun pattern:
Common Verbs
| Verb | Purpose | Example |
|---|---|---|
| Get | Retrieve data | Get-Process |
| Set | Modify settings | Set-Location |
| New | Create objects | New-Item |
| Remove | Delete objects | Remove-Item |
| Enable | Activate feature | Enable-WindowsFeature |
| Disable | Deactivate feature | Disable-FirewallRule |
| Install | Install software | Install-Module |
| Uninstall | Remove software | Uninstall-Package |
| Test | Verify condition | Test-Path |
| Move | Relocate object | Move-Item |
Parameters
Parameters modify command behavior:Pipelines
PowerShell’s pipelines pass entire objects between commands:Script Files (.ps1)
PowerShell scripts use the.ps1 extension:
Help System
PowerShell includes comprehensive help:Execution Policy
PowerShell’s execution policy controls script execution:| Policy | Description |
|---|---|
| Restricted | No scripts can run (default) |
| AllSigned | Only signed scripts can run |
| RemoteSigned | Local scripts run unsigned; downloaded scripts must be signed |
| Unrestricted | All scripts can run (prompts for downloaded scripts) |
| Bypass | No restrictions, no warnings |
BASH Shell (GNU/Linux)
BASH (Bourne Again SHell) is the default shell on most Linux distributions.The Prompt
The prompt provides information about your session:violin- usernamexubuntu- hostname~- current directory (home)$- regular user (#for root)
Key Features
Tab Completion
Tab Completion
Press
TAB to auto-complete:- Commands
- File names
- Directory names
- Variables
TAB twice to see all possibilities:Command History
Command History
Navigate command history with arrow keys:
- ↑ - Previous command
- ↓ - Next command
history- Show command history!123- Execute command #123 from history!!- Execute previous command!$- Last argument of previous command
~/.bash_history (default 1000 commands)Aliases
Aliases
Create command shortcuts:Make permanent by adding to
~/.bashrcFunctions
Functions
Define reusable functions:
Script Structure
BASH scripts follow a standard structure:Shebang Line
The shebang (#!) specifies the interpreter:
Using
#!/usr/bin/env bash is more portable as it finds bash in the PATH.Making Scripts Executable
Common BASH Constructs
Comparing PowerShell and BASH
| Task | PowerShell | BASH |
|---|---|---|
| List files | Get-ChildItem | ls |
| Change directory | Set-Location | cd |
| Copy file | Copy-Item | cp |
| Move file | Move-Item | mv |
| Delete file | Remove-Item | rm |
| Create directory | New-Item -Type Directory | mkdir |
| Display text | Write-Host | echo |
| View file | Get-Content | cat |
| Find text | Select-String | grep |
| Sort output | Sort-Object | sort |
| Filter output | Where-Object | grep |
Both shells support aliases. PowerShell includes aliases that match common BASH commands (ls, cd, cat, etc.).