Copy .php files with directory structure no directories

Hi Team,

I have copied all files from /var/www/html/media to /media without copy the directories, but failed. I have copied the .php file with their parents directory structure using following command:
find /var/www/html/media -maxdepth 1 -type -f -name “*.php” -exec cp --parents {} /media ;

all .php file are copied. why failed? thank you for any feedback.


Before your second attempt did you already click on Finish button.If so your changes after that were not considered. Please not that any changes made after clicking on finish button are not considered in the original answer.

This is my first attempt, yes, i click the finish button as I did with other successful task after the find/copy command and verified .php files along with its parents directory structure are in /media folder.

This could be the issue in your command “-maxdepth 1”. it’s just copy files from source directory not from it’s sub-directories. :slight_smile:

the task is asking not copying the .php file from the sub-directories, that is why -maxdepth 1 is used.

May be its diff for u… for me they have given two steps

  1. Copy all .php files means files from sub directories as well
  2. Including parent folders

And I used the same command without maxdepth and completed it successfully

1 Like

@Inderpreet can you give me a second attempt?

@Jenna Your command doesnt actually run as it gives an error for the argument option -type. You are really close to the correct command but you have some arguments that are unnecessary.