Bird
Raised Fist0
Linux CLIscripting~20 mins

find by name, type, and size in Linux CLI - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Find Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
Find files named 'report.txt' of type regular file
What is the output of this command if the current directory contains exactly one regular file named 'report.txt' and no other files with that name?

find . -name 'report.txt' -type f
Linux CLI
find . -name 'report.txt' -type f
A./report.txt
B
./report.txt/
./report.txt
Creport.txt
DNo output
Attempts:
2 left
💡 Hint
The command finds regular files named exactly 'report.txt' in the current directory and subdirectories.
💻 Command Output
intermediate
1:30remaining
Find directories named 'backup' larger than 1MB
What will this command output if there is one directory named 'backup' with size 2MB and one file named 'backup' with size 3MB?

find . -name 'backup' -type d -size +1M
Linux CLI
find . -name 'backup' -type d -size +1M
A./backup/file.txt
B
./backup
./backup/file.txt
CNo output
D./backup
Attempts:
2 left
💡 Hint
The command looks for directories named 'backup' larger than 1MB, not files.
📝 Syntax
advanced
2:00remaining
Correct find command to locate regular files named '*.log' smaller than 500KB
Which option is the correct find command to locate regular files with names ending in '.log' and size less than 500KB?
Afind . -name '*.log' -type f -size -500k
Bfind . -name '*.log' -type f -size +500k
Cfind . -type f -name '*.log' -size -500k
Dfind . -name '*.log' -type d -size -500k
Attempts:
2 left
💡 Hint
Order of options does not matter, but size sign and type must be correct.
🔧 Debug
advanced
2:00remaining
Why does this find command fail to find files larger than 1MB?
Given this command:

find /data -type f -name '*.csv' -size +1M

It returns no results even though there are CSV files larger than 1MB. What is the most likely reason?
Linux CLI
find /data -type f -name '*.csv' -size +1M
AThe size option counts 512-byte blocks, so '+1M' means files larger than 1*512 bytes
BThe '+1M' means files larger than 1MB, so it should be '-1M' to find larger files
CThe size unit 'M' is case sensitive and should be lowercase 'm'
DThe command is correct; the files are probably smaller than 1MB
Attempts:
2 left
💡 Hint
Check how the find command interprets size units by default.
🚀 Application
expert
2:30remaining
Find all empty directories named 'temp' and delete them safely
Which command will find all empty directories named 'temp' under /var/log and delete them safely, prompting before each deletion?
Afind /var/log -type d -name 'temp' -empty -delete
Bfind /var/log -type d -name 'temp' -empty -exec rm -ri {} +
Cfind /var/log -type d -name 'temp' -empty -exec rm -r {} \;
Dfind /var/log -type d -name 'temp' -empty -exec rm -i {} \;
Attempts:
2 left
💡 Hint
You want to delete directories safely with confirmation and only empty ones named 'temp'.

Practice

(1/5)
1. What does the find command option -name do in Linux CLI?
easy
A. Searches files or directories by their name pattern
B. Filters files by their size
C. Lists all files in the current directory
D. Changes the name of a file

Solution

  1. Step 1: Understand the -name option

    The -name option in the find command is used to search for files or directories that match a specific name pattern.
  2. Step 2: Compare with other options

    Options like filtering by size or listing files are done with other flags, not -name.
  3. Final Answer:

    Searches files or directories by their name pattern -> Option A
  4. Quick Check:

    -name = Search by name [OK]
Hint: Remember: -name matches file names exactly [OK]
Common Mistakes:
  • Confusing -name with size filters
  • Thinking -name lists files
  • Using -name to rename files
2. Which of the following is the correct syntax to find all regular files named report.txt in the current directory and its subdirectories?
easy
A. find . -type f -name report.txt
B. find . -name "report.txt" -type d
C. find . -type f -name "report.txt"
D. find / -type f -name report.txt

Solution

  1. Step 1: Understand the syntax for find

    The correct syntax requires the path (here . for current directory), the type -type f for regular files, and the name pattern with quotes -name "report.txt" to match the exact file name.
  2. Step 2: Check each option

    find . -type f -name report.txt misses quotes around the name, which can cause issues with special characters. find . -name "report.txt" -type d searches for directories (-type d) not files. find / -type f -name report.txt searches from root /, not current directory. find . -type f -name "report.txt" is correct with quotes and correct type.
  3. Final Answer:

    find . -type f -name "report.txt" -> Option C
  4. Quick Check:

    Quotes + correct type + current dir = find . -type f -name "report.txt" [OK]
Hint: Always quote the name pattern to avoid shell issues [OK]
Common Mistakes:
  • Omitting quotes around the name
  • Using wrong type flag (-type d instead of -type f)
  • Searching from wrong directory
3. What will be the output of the command find /tmp -type f -size +1M -name "*.log" assuming there are two files: /tmp/app.log (500K) and /tmp/error.log (2M)?
medium
A. /tmp/app.log /tmp/error.log
B. /tmp/error.log
C. /tmp/app.log
D. " (no output)

Solution

  1. Step 1: Understand the command filters

    The command searches in /tmp for regular files (-type f) with size greater than 1 megabyte (-size +1M) and names ending with .log (-name "*.log").
  2. Step 2: Apply filters to given files

    /tmp/app.log is 500K, which is less than 1M, so excluded. /tmp/error.log is 2M, which matches size and name filters, so included.
  3. Final Answer:

    /tmp/error.log -> Option B
  4. Quick Check:

    Size +1M and name *.log = /tmp/error.log [OK]
Hint: Size +1M means files larger than 1 megabyte [OK]
Common Mistakes:
  • Including files smaller than 1M
  • Ignoring the name pattern
  • Confusing +1M with exactly 1M
4. You run the command find . -type f -name *.txt -size -10k but get an error or unexpected results. What is the likely problem?
medium
A. The command needs sudo to run
B. Wrong size flag; should be +10k instead of -10k
C. Using -type f instead of -type d
D. Missing quotes around *.txt causing shell expansion

Solution

  1. Step 1: Identify the issue with -name pattern

    The pattern *.txt without quotes is expanded by the shell before find runs, causing unexpected behavior or errors.
  2. Step 2: Correct usage with quotes

    Enclosing *.txt in quotes like "*.txt" prevents shell expansion and lets find correctly match file names.
  3. Final Answer:

    Missing quotes around *.txt causing shell expansion -> Option D
  4. Quick Check:

    Always quote patterns in -name [OK]
Hint: Quote wildcards in -name to avoid shell expansion [OK]
Common Mistakes:
  • Not quoting the name pattern
  • Confusing size flags + and -
  • Using wrong type flag
5. You want to find all directories named backup larger than 100MB inside /var. Which command correctly achieves this?
hard
A. find /var -type d -name "backup" -size +100M -exec du -sh {} \;
B. find /var -type d -name "backup" -size +100M
C. find /var -type d -name "backup" -exec du -sh {} \; | awk '$1 > 100M'
D. find /var -type d -name "backup" -size +100M -size +100M

Solution

  1. Step 1: Understand find limitations on directory size

    The -size option measures file size, but for directories it measures disk usage metadata, not total content size.
  2. Step 2: Use -exec du -sh to get actual directory size

    find /var -type d -name "backup" -size +100M -exec du -sh {} \; uses -exec du -sh {} to show human-readable size of each directory found, which helps verify size over 100MB.
  3. Step 3: Confirm correct filtering

    find /var -type d -name "backup" -size +100M incorrectly uses -size +100M on directories which is unreliable. find /var -type d -name "backup" -exec du -sh {} \; | awk '$1 > 100M' tries to filter with awk but size format is not numeric only. find /var -type d -name "backup" -size +100M -size +100M repeats -size +100M unnecessarily.
  4. Final Answer:

    find /var -type d -name "backup" -size +100M -exec du -sh {} \; -> Option A
  5. Quick Check:

    Use -exec du -sh to check directory sizes [OK]
Hint: Use du with -exec to measure directory size [OK]
Common Mistakes:
  • Relying on -size for directory content size
  • Not quoting the name pattern
  • Repeating size filters unnecessarily
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard