Course outline
Course / The terminal and the language

Find big and recently changed files

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-06-find-by-size-and-age
cd 02-06-find-by-size-and-age
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 of different sizes that were changed at different times. Print two sorted lists of files: first the ones bigger than 1 kilobyte, then a separator line, then the ones changed within the last 2 days.

Example

If testdata held big.log (3 KB, changed last week) and new.txt (10 bytes, changed an hour ago), your script prints:

testdata/big.log
---
testdata/new.txt

Rules

  • Edit answer.sh. Search from testdata and list regular files only (-type f).
  • Each list is sorted with | sort. The separator is a line containing only --- (echo "---").
  • testdata/ is created fresh each time you run the test, so the file times are always current. Run the test once to see the files, then look inside the folder.
  • find rounds sizes up to the next whole unit, so a 1,025-byte file counts as 2k.

What you'll practice

find -size and find -mtime.

Run it

gonomicon fetch week-1/02-06-find-by-size-and-age
cd 02-06-find-by-size-and-age
gonomicon test
gonomicon submit

Hints

  1. -size +1k means bigger than 1 kilobyte. -mtime -2 means changed less than 2 days ago.
  2. Add -type f so only real files show up, not folders.
  3. Print the separator with echo "---" and sort each list.

Something wrong with this lesson? Report a problem