Red Hat Certified System Administrator RHCSA · Free Practice Question Medium

Question 24

On ServerB, find all regular files owned by the root user in the /usr/ directory and copy these files into the /find/rootfiles/ directory. Ensure that the files are copied successfully and verify the results.

  • A

    Pass

  • B

    Fail

Reveal correct answer

Correct answer: A

Explanation

Answer:

To locate and copy regular files owned by the root user from /usr/ into /find/rootfiles/, follow these steps:

  1. Create the Target Directory:

    • Explanation: The mkdir -p command creates the specified directory. The -p option ensures that any missing parent directories are created automatically, making this command safe to use even if /find doesn’t exist yet.

  2. Find and Copy Files Owned by Root in /usr/:

    • Explanation of Each Part:

      • find: Searches for files based on specified criteria.

      • /usr/: Defines the starting directory for the search.

      • -type f: Restricts the search to regular files, excluding directories and other file types.

      • -user root: Limits the results to files owned by the root user.

      • -exec: Executes a command on each file found by find.

      • cp {} /find/rootfiles/: Copies each found file (represented by {}) into /find/rootfiles/.

      • ;: Terminates the -exec command.

  3. Verify the Copied Files:

    • Explanation: The ls -l command lists all files in /find/rootfiles/ with detailed information, such as permissions, ownership, and file size. This verifies that each file was copied successfully and retains its original attributes.

Additional Notes:

  • Common Errors and Troubleshooting:

    • File Permissions: Ensure you have root privileges to access files in /usr/ and create directories in /find/.

    • Verifying Ownership: After copying, confirm the files are owned by root in /find/rootfiles/. This ensures that file ownership and permissions were preserved during the copy.

  • Alternative Approach:

    • If there are a large number of files, consider using rsync with the appropriate flags, as it can handle large batch copies efficiently while preserving attributes.

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