Hi , Following day 4 of Linux chanllenges, I did copy exactly as the questions asked, but got it wrong, but the command cp -a *.php /blog would copy all files owned by user anita to /blog folder. Why its wrong?
The command that you’ve shared cp -a *.php /blog, copies all .php files from the current directory to /blog. It doesn’t have anything to do with user anita that you’ve mentioned.
From what you have shared I suppose, you would have to find all the files owned by that user and then copy them to specified destination while preserving the folder structure.
@rob_kodekloud / @Srikanth_Reddy - I am also facing the same issues tried multiple option .What am i missing.
sudo find /home/usersdata  -type f -user anita -exec cp --parents -p {} /blog/ \;
This should find only files related to anita also it preservers the folder structure
Example :
/home/usersdata --> /home/usersdata/blog/home/usersdata/(files related to anita)
You almost got it. However the folder structure is a bit off.
Locate all files (excluding directories) owned by user anita within the /home/usersdata directory on App Server 1. Copy these files while preserving the directory structure to the /blog directory.
It shouldn’t be:
/home/usersdata --> /home/usersdata/blog/home/usersdata/(files related to anita)
rather it should be:
/home/usersdata/(files related to anita) --> /blog/(files related to anita)
One way of doing it would be using the relative path. Instead of doing sudo find /home/userdata .... , you can cd to the /home/userdata and then try to copy.
Note: /blog is different from /home/userdata/blog.
@Srikanth_Reddy - Thank you .Finally it worked.
cd /home/usersdata/
find . -path ./beta -prune -o -type f -user yousuf -exec cp --parents -p {} /home/usersdata/beta/ \;