Course / The terminal and the language
Find files and directories by name and type
How to fetch and submit this lab
Once: install the tool and connect your account.
curl -fsSL https://gonomicon.com/install.sh | sh
gonomicon loginEach 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 submitGoal
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 fromtestdata, so every path starts withtestdata. - Each list is sorted (
| sort).findhas no order of its own. - The separator is a line containing only
---. Print it withecho "---"(echoprints text). - The directory list includes
testdataitself.
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
find FOLDER -name "*.log" -type flists files whose name ends in .log.find FOLDER -type dlists directories, including FOLDER itself.- Sort both lists, and print the separator with
echo "---".