Red Hat Certified System Administrator RHCSA · Free Practice Question Easy
Question 21
On ServerB, find all files in the /etc directory that are larger than 5MB and copy them to /find/5mfiles.
-
A
Pass
-
B
Fail
Reveal correct answer
Correct answer: A
Explanation
Solution:
Create the Target Directory:
Begin by creating the
/find/5mfilesdirectory where the files will be copied.
- # mkdir -p /find/5mfiles
The
-poption ensures that any necessary parent directories are created automatically if they don’t already exist, preventing errors if the/finddirectory is missing.
Search for Files Larger than 5MB in
/etc:First, confirm the search results by finding all files in the
/etcdirectory (and its subdirectories) that are larger than 5MB.
- # find /etc -size +5M
Explanation:
find /etc: Searches within the/etcdirectory.-size +5M: Filters files larger than 5 megabytes (MB).This command is helpful to preview the files before performing the copy operation.
Find and Copy Files Simultaneously:
To streamline the process, use
findwith-execto directly copy files larger than 5MB to/find/5mfiles.
- # find /etc -size +5M -exec cp {} /find/5mfiles/ \;
Command Breakdown:
find /etc: Starts the search within the/etcdirectory.-size +5M: Finds files that are over 5MB.-exec cp {} /find/5mfiles/ \;: The-execaction runs thecpcommand for each file found that meets the size criteria.{}is a placeholder that represents each file found byfind.\;marks the end of the command executed by-exec.
Verify the Copied Files:
After running the command, check the contents of
/find/5mfilesto confirm the files have been copied successfully.
- # ls /find/5mfiles
This command lists the files in
/find/5mfiles, allowing you to verify that all files larger than 5MB from/etcwere correctly copied.
Additional Notes:
Previewing Files:
Running
find /etc -size +5Mfirst without-execcan be beneficial, as it provides a list of files that will be copied. This preview ensures accuracy before executing thecpcommand.
Efficiency of
-exec:The
-execoption is powerful for performing actions like copying directly within thefindcommand, saving time by eliminating the need for separate commands.
File Size Precision:
Ensure you understand that
-size +5Mrefers specifically to files strictly larger than 5MB.
Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
