Linux vs Windows and macOS: Key Differences
⚖️ Comparison of Linux with Other Operating Systems
Linux, along with Microsoft Windows and Apple macOS, forms the triad of major operating systems. For exam purposes, the comparison focuses on their fundamental differences in cost, source model, security, and primary use case.
Fundamental Distinctions (Source Model & Cost)
| Feature | Linux (e.g., Ubuntu, Fedora) | Microsoft Windows (Proprietary) | Apple macOS (Proprietary) |
|---|---|---|---|
| Source Model | Open source (source code is freely available, modifiable, and distributable). | Closed source (proprietary; source code is hidden). | Closed source (proprietary; based on a BSD UNIX core). |
| Cost | Free to obtain and use. | Requires a paid license. | Included with Apple hardware (which is typically costly). |
| Licensing | Governed by licenses like the GPL (General Public License), granting four freedoms. | Governed by an EULA (End-User License Agreement), restricting usage and modification. | Governed by an EULA. |
| Hardware | Most flexible; runs on many architectures (x86, ARM, etc.), often reviving old hardware. | Runs on a vast range of PC hardware. | Least flexible; typically runs exclusively on Apple hardware. |
Technical and Use-Case Comparison
| Feature | Linux | Windows | macOS |
|---|---|---|---|
| Security | Highest. Robust UNIX-like permissions, rapid community-driven patch cycles, and a less common target for mainstream malware. | Moderate. Most frequent target for malware due to a massive user base. | High. Strong security based on its UNIX foundation. |
| Stability | Highest. Known for continuous uptime (years) in server environments. | High in modern versions, but historically prone to issues. | High; known for reliability and a polished user experience. |
| File System | Case-sensitive (e.g., File.txt ≠ file.txt). | Case-insensitive (e.g., File.txt = file.txt). | Case-insensitive by default, but supports case-sensitive volumes. |
| Primary Shell | Bash (most common), Zsh, Fish — powerful and scriptable. | PowerShell / Command Prompt (or Bash via WSL). | Zsh (modern default) / Bash — powerful, UNIX-like. |
| Primary Use | Servers, cloud computing, embedded systems, software development, academic research. | General desktop, gaming, corporate/business productivity. | Creative professionals (video/audio/design), consumer desktop. |
Conclusion for Exam Purposes
In an examination, when comparing Linux to its proprietary counterparts, the core points to emphasize are:
- Open Source vs. Proprietary: Linux’s transparency and freedom of modification (GPL).
- Stability and Security: Linux’s multi-user/multitasking design and stringent permission model make it fundamentally more robust for mission-critical tasks (servers).
- Command Line Power: The highly efficient and essential command-line interface (CLI), typically Bash, provides a level of control and automation superior for professional IT and development work.
💻 Essential Linux Commands
This list categorizes key Linux commands crucial for system administration and development, focusing on their function and common usage.
1. General-Purpose Commands
These commands handle basic system interaction, documentation, and information retrieval.
| Command | Function | Key Option/Usage |
|---|---|---|
man | Displays the manual page (documentation) for any command or system component. | man ls |
info | Provides more detailed, structured documentation than man. | info bash |
date | Displays or sets the system time and date. | date |
who | Shows who is currently logged in to the system. | who |
clear | Clears the terminal screen. | clear |
echo | Prints text or variables to the standard output. | echo $PATH |
2. Directory-Oriented Commands (Navigation & Structure)
These commands manage the hierarchical file-system structure.
| Command | Function | Key Option/Usage |
|---|---|---|
pwd | Prints working directory (shows current location). | pwd |
cd | Changes directory. | cd /home/user or cd .. (up one level) |
ls | Lists directory contents. | ls -l (long format) or ls -a (all files, including hidden) |
mkdir | Makes a new directory. | mkdir new_folder |
rmdir | Removes an empty directory. | rmdir empty_folder |
tree | Displays directory contents in a tree-like format (if installed). | tree /etc |
3. File-Oriented Commands (Manipulation & Content)
These commands handle file creation, copying, moving, deleting, and content viewing.
| Command | Function | Key Option/Usage |
|---|---|---|
touch | Creates an empty file or updates file timestamps. | touch newfile.txt |
cat | Concatenates and prints file contents to the terminal. | cat file.txt |
less | Views large files one screen at a time (allows scrolling). | less logfile.log |
cp | Copies files and directories. | cp source.txt dest/ |
mv | Moves (renames) files and directories. | mv oldname.txt newname.txt |
rm | Removes (deletes) files. | rm file.txt or rm -rf directory (force recursive delete) |
grep | Searches for a pattern within file contents. | grep "keyword" file.txt |
find | Searches for files and directories based on various criteria. | find /home -name "*.log" |
4. Process-Oriented Commands
These commands manage and monitor running programs (processes).
| Command | Function | Key Option/Usage |
|---|---|---|
ps | Reports a snapshot of the currently running processes. | ps aux (shows all processes) |
top | Displays processes dynamically in real time (CPU/Memory usage). | top |
htop | An interactive, improved version of top (if installed). | htop |
kill | Sends a signal (e.g., termination) to a process using its PID (Process ID). | kill 1234 (default is signal 15, graceful termination) |
killall | Sends a signal to all processes with a specific name. | killall firefox |
& | Executes a command in the background. | sleep 60 & |
5. Communication-Oriented Commands
These commands facilitate user-to-user communication or network interaction.
| Command | Function | Key Option/Usage |
|---|---|---|
ssh | Secure Shell: securely logs into a remote system. | ssh user@server_ip |
scp | Secure Copy: securely transfers files between hosts. | scp localfile.txt user@server:/tmp |
ping | Tests network connectivity and measures packet round-trip time. | ping google.com |
wget | Non-interactively retrieves files from the web (downloading). | wget <URL> |
write | Sends a message to another user’s terminal session. | write username |
wall | Write to all logged-in users’ terminals (administrator announcements). | wall "System maintenance in 1 hour" |
🔎 Regular Expressions & Filters in Linux
Filters and regular expressions (regex) are fundamental tools in Linux for processing text data, especially when dealing with command output, logs, and configuration files.
🔧 Simple Linux Filters
In Linux, a filter is a program that reads data from standard input (stdin), processes it, and writes the resulting data to standard output (stdout). Filters are often used in combination with the pipe operator (|).
| Command | Function | Key Option/Usage | Example |
|---|---|---|---|
more | Used to display text output one screenful at a time. | ls -l | more | |
wc | Word count: prints the number of lines, words, and bytes (characters) in a file. | wc -l file.txt | Counts only the lines in file.txt. |
diff | Finds the differences between two files, line by line. | diff file1.txt file2.txt | Shows which lines differ and how to change them. |
sort | Sorts the lines of text files. | sort -r data.txt | Sorts the lines in data.txt in reverse alphabetical order. |
uniq | Reports or omits repeated lines. It only works on adjacent identical lines, so it is often used after sort. | sort names.txt | uniq | |
grep | Global Regular Expression Print: searches for lines matching a specified pattern (regular expression). | grep -i "error" logfile.log | Searches for “error” case-insensitively in the log file. |
📜 Introducing Regular Expressions (Regex)
Regular expressions are specialized text strings used to describe and match patterns in other strings or text files. They are essential for advanced searching and data manipulation, especially with tools like grep, sed, and awk.
Basic Regex Components
Regex uses special characters, called metacharacters, to define patterns:
| Metacharacter | Description | Example Pattern | Matches |
|---|---|---|---|
. (dot) | Matches any single character (except a newline). | a.c | abc, a1c, a-c |
* | Matches the preceding item zero or more times. | a*b | b, ab, aaab |
+ | Matches the preceding item one or more times (used with egrep/PCRE). | a+b | ab, aaab (but not b) |
? | Matches the preceding item zero or one time (used with egrep/PCRE). | colou?r | color, colour |
^ | Matches the pattern at the beginning of a line. | ^Start | Matches “Start line” but not “The Start line” |
$ | Matches the pattern at the end of a line. | End$ | Matches “Line End” but not “End of line” |
[ ] | Character set: matches any one of the characters inside the brackets. | [abc] | Matches a, b, or c |
[^ ] | Negated character set: matches any character not inside the brackets. | [^0-9] | Matches any non-digit character. |
Regex Tools in Linux
The grep utility supports three main types of regular expressions:
- Basic Regular Expressions (BRE): The default for the standard
grepcommand. It requires metacharacters like+,?,|, and{}to be escaped with a backslash (\).Example:grep "a\{2,\}b" filematches ‘a’ appearing 2 or more times followed by ‘b’. - Extended Regular Expressions (ERE): Enabled using the
egrepcommand or thegrep -Eoption. This syntax simplifies usage by allowing metacharacters like+,?, and|to be used without escaping.Example:egrep "a+b" filematches ‘a’ appearing 1 or more times followed by ‘b’. - Perl Compatible Regular Expressions (PCRE): Enabled using
grep -P. This provides the most modern and powerful set of regex features.
🧠 Example Usage
To find all lines in a file that start with an uppercase letter followed by any number of lowercase letters:
grep -E "^[A-Z][a-z]*" mydata.txtgrep -E: uses extended regular expressions.^: matches the beginning of the line.[A-Z]: matches one uppercase letter.[a-z]*: matches zero or more lowercase letters.
