Bash脚本可在文件层次结构中查找特定文件 [英] Bash script to find specific files in a hierarchy of files

查看:85
本文介绍了Bash脚本可在文件层次结构中查找特定文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件夹,其中有很多文件夹,而在每个文件夹中,我都有很多文件.我不知道每个文件可能位于哪个文件夹.我会定期收到需要复制到预定义目标位置的文件列表.

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.

该脚本将在Unix计算机上运行.

The script will run on a Unix machine.

所以,我的小脚本应该:

So, my little script should:

  • 阅读收到的清单
  • 找到列表中的所有文件
  • 通过SCP将每个文件复制到预定义的目的地

第1步和第3步,我想我可以自己管理,但是第2步该怎么做?

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

我当时正在考虑使用查找"查找每个文件,并在找到文件时将其写入字符串数组.找到所有文件后,我遍历字符串数组,对每个文件位置运行"SCP"命令.

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.

我认为这应该可行,但是我从来没有写过bash脚本,所以有人可以帮助我一些入门吗?我只需要一个基本的查找"命令即可找到文件名并在找到文件后返回文件位置.

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.

推荐答案


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

这篇关于Bash脚本可在文件层次结构中查找特定文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆