RHCSA Practical Lab Series – Finding and Copying User Files

Expertise in Cloud, Networking & DevOps
Photo by Benjamin Voros / Unsplash

πŸ” Lab 10: Searching for Files by User Ownership

πŸ“Œ Objective

In this lab, you will:

βœ” Find all files owned by a specific user (alex)
βœ” Copy those files to a designated backup directory (/root/foundfiles)
βœ” Verify the copied files


πŸ“Œ Step 1: Create a Backup Directory

πŸ”Ή Create the directory where found files will be copied:

[root@node1 ~]# mkdir /root/foundfiles

πŸ“Œ Explanation:

  • mkdir /root/foundfiles β†’ Creates a directory named foundfiles inside /root.
  • This will be used to store all files owned by alex.

πŸ“Œ Step 2: Search for Files Owned by User alex

πŸ”Ή Find all files belonging to alex:

[root@node1 ~]# find / -user alex

πŸ“Œ Explanation:

  • find / β†’ Searches from the root directory / (entire system).
  • -user alex β†’ Filters results to show only files owned by alex.

βœ… If files are listed, the search was successful.


πŸ“Œ Step 3: Copy Found Files to /root/foundfiles

πŸ”Ή Use find and cp to copy all discovered files:

[root@node1 ~]# find / -user alex -exec cp -a {} /root/foundfiles \;

πŸ“Œ Explanation:

  • find / -user alex β†’ Finds files owned by alex.
  • -exec cp -a {} β†’ Copies each found file ({} represents each file).
  • /root/foundfiles \; β†’ Destination directory where files will be copied.

βœ… Once executed, all files owned by alex will be backed up to /root/foundfiles.


πŸ“Œ Step 4: Verify Copied Files

πŸ”Ή Check the contents of /root/foundfiles to ensure files were copied successfully:

[root@node1 ~]# ls -l /root/foundfiles/

πŸ“Œ Expected Output:

-rw-r--r-- 1 alex alex  1234 Mar 28 12:34 document1.txt
-rw-r--r-- 1 alex alex  5678 Mar 28 12:35 script.sh
...

βœ… If files appear, the backup was successful.

πŸ“Œ Troubleshooting:

  • If permission issues arise, try using sudo or running as root.

If no files were copied, ensure that alex owns files on the system:

[root@node1 ~]# find / -user alex

βœ… Final Summary

βœ” Searched for all files owned by alex
βœ” Created a backup directory /root/foundfiles
βœ” Successfully copied all user-owned files to the backup location


πŸ“Œ Next Lab: Extracting Specific Lines from a File πŸ“Œ Objective

πŸ“© Subscribe for more RHCSA exam labs and hands-on tutorials! πŸš€


Read more