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:

  1. Create the Target Directory:

    • Begin by creating the /find/5mfiles directory where the files will be copied.

    • The -p option ensures that any necessary parent directories are created automatically if they don’t already exist, preventing errors if the /find directory is missing.

  2. Search for Files Larger than 5MB in /etc:

    • First, confirm the search results by finding all files in the /etc directory (and its subdirectories) that are larger than 5MB.

    • Explanation:

      • find /etc: Searches within the /etc directory.

      • -size +5M: Filters files larger than 5 megabytes (MB).

      • This command is helpful to preview the files before performing the copy operation.

  3. Find and Copy Files Simultaneously:

    • To streamline the process, use find with -exec to directly copy files larger than 5MB to /find/5mfiles.

    • Command Breakdown:

      • find /etc: Starts the search within the /etc directory.

      • -size +5M: Finds files that are over 5MB.

      • -exec cp {} /find/5mfiles/ \;: The -exec action runs the cp command for each file found that meets the size criteria.

        • {} is a placeholder that represents each file found by find.

        • \; marks the end of the command executed by -exec.

  4. Verify the Copied Files:

    • After running the command, check the contents of /find/5mfiles to confirm the files have been copied successfully.

    • This command lists the files in /find/5mfiles, allowing you to verify that all files larger than 5MB from /etc were correctly copied.

Additional Notes:

  • Previewing Files:

    • Running find /etc -size +5M first without -exec can be beneficial, as it provides a list of files that will be copied. This preview ensures accuracy before executing the cp command.

  • Efficiency of -exec:

    • The -exec option is powerful for performing actions like copying directly within the find command, saving time by eliminating the need for separate commands.

  • File Size Precision:

    • Ensure you understand that -size +5M refers 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.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need