RHCSA Practical Lab Series β Finding and Copying User Files
π 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 namedfoundfiles
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 byalex
.
β 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 byalex
.-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! π