0

I want to run the following command

./mc cp --recursive local//first/second remote//first/second

I want to loop through local//first and find all directories and run ./mc cp for each directories

How can I do this?

3
  • It's not important , I just want to run a command in a loop can you help me to iterate over directory and run the command multiple time? Commented Jan 3, 2021 at 7:21
  • Why don't you just do a cp --recursive //first remote//first? The whole point of recursive is that it goes recursively through all intries below the starting directory. No need ot write a loop then. Commented Jan 4, 2021 at 13:44
  • 1
    my command is not cp it is ./mc cp Commented Jan 4, 2021 at 13:54

2 Answers 2

2

You can use find tool to do such thing

find . -type d -exec echo {} \;

your command would something be like

find . -type d -exec ./mc cp --recursive "local/{}" "remote/{}" \;
Sign up to request clarification or add additional context in comments.

Comments

1

If local//first only contains directories, this should work for you:

./mc cp -r local//first/* remote//first

For a general case you can also use find to list all directories:

find local//first -type d

Then do whatever with this list using -exec or pipe it into xargs:

find local//first -type d -path "local//first/*" -prune -exec ./mc cp --recursive {} remote//first \;

Read more in documentation (find, xargs).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.