Bash script to find specific files in a hierarchy of files

孤街醉人 提交于 2019-12-11 18:12:49

问题


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:


find $dir -name $name -exec scp {} $destination \;


来源:https://stackoverflow.com/questions/8269455/bash-script-to-find-specific-files-in-a-hierarchy-of-files

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!