Course outline
Course / The terminal and the language

Find files and directories by name and type

Lab

How to fetch and submit this lab

Once: install the tool and connect your account.

curl -fsSL https://gonomicon.com/install.sh | sh
gonomicon login

Each lab: download it, edit the file named in the instructions, then submit.

gonomicon fetch week-1/02-05-find-by-name-and-type
cd 02-05-find-by-name-and-type
gonomicon submit

Go installed? gonomicon test runs the visible test on your computer first. Submitting also runs hidden checks on our server.

Goal

The folder testdata holds files and folders. Print two sorted lists: first every file whose name ends in .log, then a separator line, then every directory.

Example

If testdata held a.log, b.txt and a folder sub, your script prints:

testdata/a.log
---
testdata
testdata/sub

Rules

  • Edit answer.sh. Search from testdata, so every path starts with testdata.
  • Each list is sorted (| sort). find has no order of its own.
  • The separator is a line containing only ---. Print it with echo "---" (echo prints text).
  • The directory list includes testdata itself.

What you'll practice

find -name, find -type, pipes, sort, and echo.

Run it

gonomicon fetch week-1/02-05-find-by-name-and-type
cd 02-05-find-by-name-and-type
gonomicon test
gonomicon submit

Hints

  1. find FOLDER -name "*.log" -type f lists files whose name ends in .log.
  2. find FOLDER -type d lists directories, including FOLDER itself.
  3. Sort both lists, and print the separator with echo "---".

Something wrong with this lesson? Report a problem