Unix Commands  «Prev  Next»
Lesson 10

Shell Script Conclusion

In this module you learned commands commonly used in shell scripts
  1. to find a file,
  2. determine file size, sort, and
  3. search file contents.

You also learned how to pause your script to display a message for several seconds, tee the output of a command to the screen and a file, and how to clear the screen. You will be using many of these commands to complete the course project.

Unix Command Descriptions

This module covered the following commands:
Command Purpose Description
find File Search Searches for files and directories based on criteria such as name, type, size, modification time, and permissions. Can execute actions on matching files.
grep Search File Contents Searches for patterns (regular expressions) inside files. Often used to find lines matching a string or pattern. Can be case-sensitive or case-insensitive.
sort Sort Data Reads input (lines from a file or standard input) and outputs them in sorted order. Can sort alphabetically, numerically, or based on custom fields.
tee Split Output Reads from standard input and writes to both standard output and one or more files simultaneously. Useful for logging output while still displaying it.
wc Count Lines, Words, Bytes Stands for "word count"; used to count the number of lines (-l), words (-w), characters (-m), or bytes (-c) in files or input streams.
clear Clear Terminal Screen Clears the visible terminal screen, making it easier to display fresh output without clutter from previous commands.
sleep Pause Execution Pauses script execution for a specified number of seconds (or fractions of a second with sleep 0.5). Useful for delays, rate-limiting, or timing tasks.
🛠️ Quick Example of How They Might Work Together in a Script
#!/bin/bash

# Find all .log files
find /var/log -name "*.log" > logfiles.txt

# Search for 'error' entries
grep "error" $(cat logfiles.txt) > errors_found.txt

# Sort the error entries
sort errors_found.txt > errors_sorted.txt

# Display sorted errors while saving them
cat errors_sorted.txt | tee error_report.txt

# Show line, word, and byte counts
wc error_report.txt

# Clear the screen
clear

# Sleep for 5 seconds before script exit
sleep 5

📌 Summary
  • find ➔ Locate files
  • grep ➔ Search inside files
  • sort ➔ Order results
  • tee ➔ Save and display output
  • wc ➔ Summarize file size/length
  • clear ➔ Clean terminal view
  • sleep ➔ Introduce controlled pauses


Key Terms

This module covered the following key terms and concepts:
  1. Options
  2. Regular expressions
  3. redirection
The next module shows how to spot some frequently found shell script errors and demonstrates techniques for ging your shell scripts.

Search Player Script - Exercise

Click the Exercise link below to begin working on the course project.
Search Player Script - Exercise

SEMrush Software 10 SEMrush Banner 10