This bash script is designed to search for directories and/or files within a specified directory, with optional filters based on name and/or type.
- Usage
- Parameters
- Examples -Search by Name -Search by Type -Search by Both Name and Type
- Notes
- What I learned
- Useful resources
- Author
./search_script.sh <search_startAt> [ -name <target_name> OR -type <target_type> ]- <search_startAt>: The starting directory for the search.
- -name <target_name>: Search for items with a specific name.
- -type <target_type>: Filter items based on type ('f' for files, 'd' for directories).
./mini_prg.sh /path/to/search -name example_file.txt./mini_prg.sh /path/to/search -type d./mini_prg.sh /path/to/search -name example_file.txt -type f- If only searching by name, the script will find all occurrences matching the specified name.
- If only searching by type, the script will find all files or directories based on the specified type.
- If searching by both name and type, the script will find items that match both criteria.
chmod +x search_script.shIn the process of creating this script, I learned:
- How to handle command-line arguments in a Bash script.
- Techniques for searching directories and filtering results based on name and type.
- Recursive function implementation for searching nested directories.
- Bash Scripting Guide - A comprehensive guide for beginners in Bash scripting.
- Bash Reference Manual - The official GNU Bash reference manual.
- Linkedin - Mohamed Abnoune
- GitHub - Mohamed Abnoune
- Frontend Mentor - @ABNmmd