0

I have a folder in which there are many many folder and in each of these I have lots and lots of files. I have no idea which folder each files might be located in. I will periodically receive a list of files I need to copy to a predefined destination.

The script will run on a Unix machine.

So, my little script should:

  • read received list
  • find all files in the list
  • copy each file to a predefined destination via SCP

step 1 and 3, I think I'll manage on my own, but how will I do step 2?

I was thinking about using "find" to locate each file and when found, write the location in a string array. When all files are found I loop through the string array, running the "SCP" command for each file-location.

I think this should work, but I've never written a bash script before so could anyone help me a little to get started? I just need a basic "find" command which finds a filename and returns the file location if the file is found.

1 Answer 1

2
find $dir -name $name -exec scp {} $destination \;
Sign up to request clarification or add additional context in comments.

3 Comments

Hi, as I said in my first post, I've never written a bash script before. So while your suggestion might work, I'd like to know what it does.. could you describe what it does exactly? :)
It finds all files in and below the directory $dir and executes the scp command with the relative path of the file as the first argument and the contents of $destination as the second argument.
ah.. so I solves both my step 2 and 3 in one? nice.. I'll give it a shot :)

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.