0
0
Linux CLIscripting~15 mins

Terminal vs GUI in Linux CLI - Hands-On Comparison

Choose your learning style9 modes available
Terminal vs GUI: Listing Files and Counting Text Files
📖 Scenario: You are working on a Linux system. Sometimes you use the graphical interface (GUI) to see files, but other times you use the terminal (command line) to do tasks faster.In this project, you will practice using the terminal to list files and count specific files, showing how the terminal can be powerful and quick compared to clicking around in a GUI.
🎯 Goal: Learn how to list files in a directory and count how many text files (.txt) are there using terminal commands.
📋 What You'll Learn
Use the ls command to list files
Use a variable to store the directory path
Use a command to count files ending with .txt
Print the count of text files
💡 Why This Matters
🌍 Real World
Knowing how to use the terminal to list and count files helps you manage files quickly without needing to open a graphical interface.
💼 Career
Many IT and developer jobs require comfort with the command line to automate tasks and work efficiently on servers or remote systems.
Progress0 / 4 steps
1
Set the directory path
Create a variable called dir_path and set it to "./documents" which is the folder you want to check.
Linux CLI
Need a hint?

Use dir_path="./documents" to set the folder path.

2
List files in the directory
Use the ls command with the variable dir_path to list all files inside the directory.
Linux CLI
Need a hint?

Use ls "$dir_path" to list files in the folder stored in dir_path.

3
Count text files in the directory
Use the ls command with dir_path and pipe it to grep to find files ending with .txt. Then use wc -l to count how many text files there are. Store this count in a variable called txt_count.
Linux CLI
Need a hint?

Use txt_count=$(ls "$dir_path" | grep ".txt$" | wc -l) to count text files.

4
Display the count of text files
Print the message "Number of text files: " followed by the value of txt_count.
Linux CLI
Need a hint?

Use echo "Number of text files: $txt_count" to show the count.