1

I want to use cp command in a script where the path structure has variable folder name.

For example:

folder structure:

Workspace/unzipped_workspace/artifactory/my_folder123243/files

Here my_folder123243 is not constant and my_folder* is the only folder in artifactory folder.

I tried using

cp -f Workspace/unzipped_workspace/artifactory/*/files ./

But this is giving me error

cp cannot stat Workspace/unzipped_workspace/artifactory/*/files: no such file or directory

How can I use cp command in my script when I have variable folder name?

  • That suggests the shell can't find any files matching that path pattern. Does ls Workspace/unzipped_workspace/artifactory/*/files find anything? Is the "Workspace" directory in the directory you're running this command from? – Gordon Davisson Aug 1 '19 at 7:48
  • By not including your script this will go nowhere. Please provide it so someone can explain what you did wrong. 1 thing: you do not use a * in a directory. you use "find" or a loop for that. – Rinzwind Aug 1 '19 at 7:50
0

You can do it using find + cp:

find Workspace/unzipped_workspace/artifactory -name files -exec cp {} ./ \;

This command does not need * since it will match all files named files in Workspace/unzipped_workspace/artifactory

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.