0
0
Linux CLIscripting~5 mins

find with -exec for actions in Linux CLI - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the -exec option do in the find command?
It allows you to run a command on each file that find locates. This means you can perform actions like deleting, moving, or printing files directly from find.
Click to reveal answer
beginner
How do you correctly end a command used with -exec in find?
You end the command with \;. This tells find where the command finishes.
Click to reveal answer
beginner
What does {} represent in the find -exec command?
It is a placeholder for the current file found by find. The command replaces {} with the file name.
Click to reveal answer
intermediate
Why might you use find . -name '*.txt' -exec rm {} \;?
This command finds all files ending with .txt in the current directory and deletes each one by running rm on them.
Click to reveal answer
intermediate
What is the difference between -exec command {} \; and -exec command {} + in find?
Using \; runs the command once per file. Using + runs the command once with all files as arguments, which can be faster.
Click to reveal answer
What symbol ends the command in find -exec?
A;
B\;
C{}
D+
In find . -exec ls -l {} \;, what does {} do?
AIs replaced by the found file name
BRuns the command in background
CEnds the command
DRepresents the current directory
Which command deletes all .log files in the current directory and subdirectories?
Arm *.log
Bfind . -name '*.log' -print
Cfind . -name '*.log' -exec rm {} \;
Dls *.log -exec rm {} \;
What is the benefit of using -exec command {} + over -exec command {} \;?
ARuns command once per file
BDeletes files faster
CPrints file names only
DRuns command once with all files as arguments
Which of these is a correct way to move all .txt files to a folder named backup?
Afind . -name '*.txt' -exec mv {} backup \;
Bfind . -name '*.txt' -exec mv backup {} \;
Cmv *.txt backup
Dfind . -exec mv {} backup \;
Explain how the -exec option works in the find command and how to use it safely.
Think about how you tell find what to do with each file it finds.
You got /4 concepts.
    Describe the difference between ending -exec with \; and + and when to use each.
    Consider performance and command compatibility.
    You got /4 concepts.