📖 Scenario: You are a system administrator learning why Linux is the backbone of the internet. You will explore simple Linux commands and concepts that show Linux's power and flexibility in managing internet services.
🎯 Goal: Build a small script that lists active network connections, filters those related to internet services, and counts them. This will help you understand how Linux manages internet traffic.
📋 What You'll Learn
Use the ss command to list network connections
Create a variable called connections to store the output of ss -tuln
Create a variable called internet_connections to filter lines containing :80 or :443
Count the number of internet connections and store it in count
Print the count with a descriptive message
💡 Why This Matters
🌍 Real World
System administrators use Linux commands and scripts like this to monitor and manage internet services on servers.
💼 Career
Understanding Linux networking commands is essential for roles in IT support, network administration, and cybersecurity.
Progress0 / 4 steps
1
List all active network connections
Create a variable called connections and assign it the output of the command ss -tuln using command substitution.
Linux CLI
Hint
Use $(command) to capture command output into a variable.
2
Filter internet service connections
Create a variable called internet_connections that filters connections to include only lines containing :80 or :443 using grep.
Linux CLI
Hint
Use grep -E ':80|:443' to match either port 80 or 443.
3
Count the filtered internet connections
Create a variable called count that counts the number of lines in internet_connections using wc -l.
Linux CLI
Hint
Use wc -l to count lines.
4
Display the count of internet connections
Print the message "Number of active internet connections: " followed by the value of count using echo.
Linux CLI
Hint
Use echo "Number of active internet connections: $count" to print the message.
The actual number may vary; for validation, zero is acceptable if no connections exist.
Practice
(1/5)
1. Why is Linux widely used to power internet servers?
easy
A. Because it is free, stable, and flexible
B. Because it is the only operating system available
C. Because it requires expensive licenses
D. Because it only runs on personal computers
Solution
Step 1: Understand Linux's cost and flexibility
Linux is free to use and can be customized easily, unlike many paid systems.
Step 2: Recognize Linux's stability for servers
Linux is known for running reliably over long periods, which is essential for internet servers.
Final Answer:
Because it is free, stable, and flexible -> Option A
Quick Check:
Linux powers servers due to freedom and stability = A [OK]
Hint: Linux is popular because it's free and reliable [OK]
Common Mistakes:
Thinking Linux is the only OS available
Believing Linux requires paid licenses
Assuming Linux only runs on personal computers
2. Which of the following is the correct command to check the Linux kernel version?
easy
A. pwd
B. ls -l
C. uname -r
D. cat /etc/passwd
Solution
Step 1: Identify command to show kernel version
The command uname -r displays the Linux kernel version.
Step 2: Check other commands' purposes
ls -l lists files, pwd shows current directory, cat /etc/passwd shows user info.
Final Answer:
uname -r -> Option C
Quick Check:
Kernel version command = uname -r [OK]
Hint: Use uname -r to see kernel version quickly [OK]
Common Mistakes:
Confusing ls -l with kernel info
Using pwd instead of uname
Trying to read unrelated files for version
3. What will be the output of the command ps aux | grep apache on a Linux server?
medium
A. Current directory contents
B. Error message about invalid command
C. System uptime information
D. List of running processes related to Apache
Solution
Step 1: Understand the ps aux command
ps aux lists all running processes on the system.
Step 2: Understand the grep apache part
grep apache filters the list to show only lines containing 'apache', showing Apache-related processes.
Final Answer:
List of running processes related to Apache -> Option D
Quick Check:
ps aux filtered by apache = running Apache processes [OK]
Hint: grep filters process list to show Apache only [OK]
Common Mistakes:
Expecting directory listing instead of processes
Thinking it shows system uptime
Assuming command will error out
4. You run the command systemctl start nginx but get an error saying 'Failed to start nginx.service: Unit not found.' What is the likely cause?
medium
A. Nginx is not installed on the system
B. You typed the command correctly and service is running
C. The systemctl command is not available on Linux
D. You need to reboot the server before starting nginx
Solution
Step 1: Analyze the error message
'Unit not found' means the service file for nginx does not exist, often because nginx is not installed.
Step 2: Check other options' validity
systemctl is standard on Linux; reboot is not required to start services; the command typed correctly but service missing.
Final Answer:
Nginx is not installed on the system -> Option A
Quick Check:
Unit not found = service missing = nginx not installed [OK]
Hint: Unit not found means service missing or not installed [OK]
Common Mistakes:
Assuming systemctl is missing
Thinking reboot fixes service start errors
Ignoring installation status of nginx
5. You want to automate daily backups on a Linux server using a script. Which Linux feature helps you schedule this task to run automatically every day at 2 AM?
hard
A. systemctl start
B. cron jobs
C. ls command
D. chmod permissions
Solution
Step 1: Identify scheduling tools in Linux
Cron is the standard Linux tool to schedule tasks to run automatically at set times.