Practice & Assessment
Test your understanding of Module 3: File Management Commands
Multiple Choice Questions
5Which command creates a directory and all necessary parent directories without error?
Which command would you use to monitor a log file in real time as new entries are added?
What does the >> operator do in Linux?
Which grep flag makes a search case-insensitive?
What is the purpose of the pipe operator (|) in Linux?
Coding Challenges
1Build a Project Directory Structure
Using a single mkdir -p command with brace expansion, create the following directory structure inside your home directory: myproject/src, myproject/tests, myproject/docs, myproject/logs. Then use touch to create a main.sh file inside src, a README.md inside myproject, and a server.log inside logs. Use echo with redirection to write the text 'Project initialized' into README.md. Finally, use grep to search for the word 'initialized' inside README.md and use ls -R myproject to display the full directory tree.
Mini Project
Log Analysis Pipeline
Create a directory called log-analysis in your home directory. Copy the system log file /var/log/syslog (or /var/log/messages on CentOS) into it. Using pipes and redirection, perform the following analysis: extract all lines containing the word 'error' (case-insensitive) and save them to errors.txt; count the total number of error lines and save the count to error-count.txt; extract the last 50 lines of the log and save them to recent.txt; use sort and uniq to find the top repeated words in the error lines and save the result to top-errors.txt. Write a brief summary of your findings into a file called analysis-summary.txt using echo and >>.
