shelllings

a practical way to learn shell
git clone https://git.davidvoz.net/shelllings.git
Log | Files | Refs | README | LICENSE

commit 0caae05ff23dc4ca8bebb72dfc25f751b29ab80c
parent 8198f598c1d5a432a5ddab806f10b2a6e6b5c30f
Author: David Voznyarskiy <davidv@no-reply@disroot.org>
Date:   Thu,  5 Feb 2026 21:19:54 -0800

exercise 32 find added to master branch

Diffstat:
Aexercises/32_find.sh | 45+++++++++++++++++++++++++++++++++++++++++++++
Atests/32_find.sh | 20++++++++++++++++++++
2 files changed, 65 insertions(+), 0 deletions(-)

diff --git a/exercises/32_find.sh b/exercises/32_find.sh @@ -0,0 +1,45 @@ +#!/bin/sh +# +# find is used to find just about anything +# +# $ find exercises/ -name 01_echo.sh +# +# There are many filters and regex you can use to help in your searches +# +# $ find ~ -type d -iname git +# +# the command above is used to find a directory named "git", including +# all uppercase and lowercase finds +# +# $ find [location] [options] [name] +# +# [location] +# anywhere you want with permission +# +# [options] +# -type x replace 'x' with f if you are looking for files, d for +# directories, l for links, b for blockdevices +# -executable can be added to search for it +# -name looks for that exact name +# -iname case insensitive +# -size +100M files larger than 100MB +# -1G small than 1GB +# -empty empty files +# -mtime -1 modified in the last day +# -amine -10 accessed in the last 10 minutes +# +# -prune requires more explanation +# $ find . -name tests -type d -prune -o -type f -print +# +# the find command looks through the current dirctory. If it name +# matches with 'tests', it will skip a recursion into it and move on +# the '-o' is the or in the command. To either skip or to print out each +# file. The -print at the end makes sure that the dir tests/ is not +# printed out. +# +# [name] +# includes regex +# +# Have the find command list out all files in the shelllings/ repo +# that have a 'oo' in the file name, exclude the .git/ folder. + diff --git a/tests/32_find.sh b/tests/32_find.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +set -eu +RED="\033[31m" +GREEN="\033[32m" +RESET="\033[0m" + +failed() { + printf "${RED}Failed${RESET}\n" + exit 1 +} + +sh exercises/32_find.sh || failed + +user_output=$(sh exercises/32_find.sh | sort) +correct_output=$(find . -name .git -prune -o -type f -name "*oo*" -print | sort) + +[ "$user_output" = "$correct_output" ] || failed + +printf "${GREEN}Passed${RESET}\n"