Command Line Interface
In the beginning… was the command line.
- Neal Stephenson (1999)
What is a Command Interpreter?
A command interpreter, also known as a Terminal, is the most basic interface between the user and the operating system and programs. It’s a program that translates commands entered by the user (typically via keyboard) using a set of commands that must be known by both the system and the user.The user must enter commands with different parameters, and when pressing Enter, the operating system interprets the character sequence and if there are no errors, executes it.
What is a Script?
A script is a file that includes a series of commands that will be executed by a command interpreter. The word script means “screenplay,” and each script can be interpreted by different actors (interpreters). In this module, we’ll work extensively with:- PowerShell (Windows)
- BASH (GNU/Linux)
Creating Scripts
A script is created using a plain text editor:- Windows: Notepad.exe or PowerShell ISE
- GNU/Linux: nano, vim, or other text editors
Script Structure
First Line (Shebang)
On UNIX systems, the first line contains the path to the interpreter:For PowerShell:
PowerShell
Key Features
- Object-oriented: Everything is an object, not just text strings
- Uses .NET Framework: Rich programming capabilities
- Open Source: MIT license since version 6
- Cross-platform: Available on Linux and macOS
cmdlets
Basic commands in PowerShell follow the<Verb>-<Noun> pattern:
| Verb | Action |
|---|---|
| Enable | Enable the object |
| Disable | Disable the object |
| Install | Install the object |
| Uninstall | Uninstall the object |
| Move | Move the object |
| New | Create information |
| Get | Obtain information |
| Set | Modify information |
| Test | Test information |
| Remove | Delete information |
Parameters
Pipelines
One of the most powerful concepts - pass output from one command as input to another:Help System
Execution Policy
To enable script execution:BASH Shell in GNU/Linux
When opening a terminal in Linux, you see a shell prompt:- User: violin
- Hostname: xubuntu
- Current directory: ~ (home)
- User type: $ (regular user, # for root)
BASH Features
Auto-completion
Auto-completion
Press TAB to auto-complete commands, filenames, or variables. Press TAB twice to see all possibilities.
Command History
Command History
Use arrow keys to navigate through previously executed commands (up to 1000 by default).
Control Structures
Control Structures
Use if, for, while, select, case statements for powerful scripting.
Functions and Aliases
Functions and Aliases
Define custom functions and create command aliases for frequently used operations.
Process Management
What is a Process?
According to UPV’s Operating Systems department: “A process is a program in execution.” From the OS perspective, a process is an object that must be managed and serviced.Process Lifecycle
When a program executes:- OS checks permissions
- Allocates RAM space
- Assigns CPU time (priority)
- Process accesses instructions and performs tasks
As administrators, we need to know how to obtain process information for monitoring, security audits, network usage analysis, etc.
Processes in Windows
Task Manager
Access via:Ctrl+Alt+Del- Right-click Start button → Task Manager
Key Tabs
Processes- Shows applications and background processes
- Resource usage: CPU, Memory, Disk, Network
- System performance graphs
- Uptime
- Active processes count
- CPU and memory statistics
- Programs that launch at startup
- Impact on boot time
- Good place to check for malware
| Column | Meaning |
|---|---|
| Name | Executable name |
| PID | Process identifier |
| Status | Process status |
| User name | User who launched the process |
| CPU | CPU usage percentage |
| Memory | RAM usage |
| Description | Executable description |
- Running system services
- Background processes (Windows Defender, Print Spooler, etc.)
Other Tools
- Process Explorer: Advanced process monitoring
- PowerShell: Command-line process management
Processes in GNU/Linux
Command: ps
Shows active processes:Command: pstree
Shows process tree:Command: top
Real-time process monitoring:- CPU usage
- Memory available/consumed
- Uptime
- Process details
Command: kill
Send signals to processes:Command: killall
Stop all instances by name:Command: nice
Set process priority (-20 to 19):- -20: Highest priority
- 0: Default priority
- 19: Lowest priority
Network Configuration
MAC Address
Physical address identifying network adapter (48 bits):IP Address (IPv4)
Logical and hierarchical identifier for network interfaces.Static IP
Manual configuration requires:- Address: IP address
- Subnet Mask: Network mask
- Gateway: Default gateway
- DNS Servers: Name resolution
Dynamic IP (DHCP)
Automatic configuration via DHCP server.Network Configuration in Windows
Access via:- Control Panel → Network and Sharing Center
- Network adapter properties
Connection Details
- IPv4 Connectivity: IPv4 network connection status
- IPv6 Connectivity: IPv6 network connection status
- Media State: Device enabled status
- Duration: Time device has been enabled
- Speed: Transfer rate
Activity Monitoring
- Bytes sent/received
- Useful indicator of connection health
Workgroups and Domains
Domain- Group of computers sharing database and security policy
- Centrally managed
- Requires password/credentials for access
- Peer-to-peer network
- No central control
- Each computer has own user accounts
- Typically ≤20 computers
Network Configuration in GNU/Linux
netplan (Ubuntu 18.04+)
Configuration files in/etc/netplan/*.yaml
netplan Commands
Network Commands
tracepathBe careful when changing hostname - programs like sudo may rely on it.