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:
Create the Target Directory:
- # mkdir -p /find/rootfiles
Explanation: The
mkdir -pcommand creates the specified directory. The-poption ensures that any missing parent directories are created automatically, making this command safe to use even if/finddoesn’t exist yet.
Find and Copy Files Owned by Root in
/usr/:- # find /usr/ -type f -user root -exec cp {} /find/rootfiles/ \;
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
-execcommand.
Verify the Copied Files:
- # ls -l /find/rootfiles/
Explanation: The
ls -lcommand 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
rsyncwith 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.
