bash脚本 - 在目录复制最新版本的文件递归 [英] Bash Script - Copy latest version of a file in a directory recursively

查看:200
本文介绍了bash脚本 - 在目录复制最新版本的文件递归的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面,我想找到最新的版本,可以在多个目录中的文件。

Below, I am trying to find the latest version of a file that could be in multiple directories.

示例目录:

~inventory/emails/2012/06/InventoryFeed-Activev2.csv    2012/06/05
~inventory/emails/2012/06/InventoryFeed-Activev1.csv    2012/06/03
~inventory/emails/2012/06/InventoryFeed-Activev.csv     2012/06/01

继承人的bash脚本:

Heres the bash script:

#!/bin/bash

FILE = $(find ~/inventory/emails/ -name INVENTORYFEED-Active\*.csv | sort -n | tail -1)
#echo $FILE #For Testing

cp $FILE ~/inventory/Feed-active.csv;

我得到的错误是:

The error I am getting is:

./inventory.sh: line 5: FILE: command not found

如上试图脚本应该复制的最新文件。

The script should copy the newest file as attempted above.

两个问题:

首先,这是才达到我想要的最好的方法是什么?
其次,上述错误请告诉我?

First, is this the best method to achive what I want? Secondly, Whats wrong above?

推荐答案

它看起来不错,但你周围的 = 标志位。这是行不通的。尝试:

It looks good, but you have spaces around the = sign. This won't work. Try:

#!/bin/bash

FILE=$(find ~/inventory/emails/ -name INVENTORYFEED-Active\*.csv | sort -n | tail -1)
#echo $FILE #For Testing

cp $FILE ~/inventory/Feed-active.csv;

这篇关于bash脚本 - 在目录复制最新版本的文件递归的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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