LINUX · Files & search · 8 min

Find logs across nested folders

Select files by type and extension without losing directory names.

Not completed

Your task

Write a sorted list of .log files under this folder to logs.list. Include archived logs but exclude notes.txt and directories.

What you’re aiming for

  • logs.list contains exactly ./archive/old.log and ./incoming/app.log.
  • The source files are unchanged.

1. Prepare your practice folder

Use a Linux terminal, such as Ubuntu or WSL on Windows. These examples use Linux file permissions. In WSL, create your practice folder in your Linux home directory (~).

Create a new, empty folder for this exercise. If that name already exists, choose another new name. Continue only after you’re inside the new folder.

NEW PRACTICE FOLDER
mkdir opsrung-linux-find-log-files && cd opsrung-linux-find-log-files

Run these setup commands in that folder:

SETUP — RUN ONCE
mkdir incoming archive
printf '%s\n' 'INFO active' > incoming/app.log
printf '%s\n' 'INFO archived' > archive/old.log
printf '%s\n' 'Do not select this.' > incoming/notes.txt

2. Try the task

Work toward the goal above. Start by inspecting the files or resources, then use a hint if you need one.

Hint 1

find can walk nested folders.

Hint 2

Use -type f and quote the filename pattern.

Hint 3

Pipe the result through sort into a different file.

3. Review your result

Use these commands to look at your result and compare it with the goals. The website does not run or verify them.

REVIEW IN YOUR TERMINAL
cat logs.list
cat incoming/app.log archive/old.log

What you should see

  • logs.list contains exactly ./archive/old.log and ./incoming/app.log.
  • The source files are unchanged.

If your result differs: Compare the actual output with each goal. Keep your work inside this exercise’s folder and use only its named resources.

Compare with one possible solution
ONE POSSIBLE SOLUTION
find . -type f -name '*.log' | sort > logs.list

Other approaches are fine if you reach the same goal. Opening this solution does not mark the exercise complete.

Finished this exercise?

You decide when you’re done. Your choice is saved in this browser, and you can change it later.