0
0
Linux CLIscripting~20 mins

find with -exec for actions in Linux CLI - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Find with Exec Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of find with -exec to list files
What is the output of this command if the current directory contains files file1.txt and file2.log only?

find . -name '*.txt' -exec ls -l {} \;
Linux CLI
find . -name '*.txt' -exec ls -l {} \;
ANo output, command fails
BLists detailed info of file2.log only
CLists detailed info of file1.txt only
DLists detailed info of both file1.txt and file2.log
Attempts:
2 left
💡 Hint
The command finds files ending with .txt and runs ls -l on each.
💻 Command Output
intermediate
2:00remaining
Effect of find with -exec rm on files
Given a directory with files a.txt, b.txt, and c.log, what files remain after running?

find . -name '*.txt' -exec rm {} \;
Linux CLI
find . -name '*.txt' -exec rm {} \;
AOnly c.log remains
BAll files remain
COnly a.txt remains
DOnly b.txt remains
Attempts:
2 left
💡 Hint
The command deletes files ending with .txt.
📝 Syntax
advanced
2:00remaining
Correct syntax for find with -exec to move files
Which option correctly moves all .log files to /backup using find with -exec?
Afind . -name '*.log' -exec mv {} /backup \;
Bfind . -name '*.log' -exec mv {} /backup ;
Cfind . -name '*.log' -exec mv {} /backup \
Dfind . -name '*.log' -exec mv {} /backup
Attempts:
2 left
💡 Hint
The -exec command must end with an escaped semicolon.
🔧 Debug
advanced
2:00remaining
Why does this find with -exec command fail?
This command is intended to compress all .txt files with gzip:

find . -name '*.txt' -exec gzip {} ;

Why does it fail?
Linux CLI
find . -name '*.txt' -exec gzip {} ;
AThe find command needs -print before -exec
Bgzip command does not accept file arguments
CThe wildcard '*.txt' is not quoted
DMissing escape before semicolon causes syntax error
Attempts:
2 left
💡 Hint
Check how the semicolon is written at the end of -exec.
🚀 Application
expert
3:00remaining
Count files modified in last 7 days and delete them
Which command correctly finds files modified in the last 7 days and deletes them safely using find with -exec?
Afind . -type f -mtime 7 -exec rm {} \;
Bfind . -type f -mtime -7 -exec rm -i {} \;
Cfind . -type f -mtime +7 -exec rm -f {} \;
Dfind . -mtime -7 -exec rm {}
Attempts:
2 left
💡 Hint
Use -mtime with negative value for files modified within last N days and confirm deletion.