【问题标题】:move files which are older than X days to target directory in HDFS将超过 X 天的文件移动到 HDFS 中的目标目录
【发布时间】:2017-08-19 03:57:44
【问题描述】:

我有一个源文件夹,它由嵌套的子目录组成。我想移动所有超过 2 天的 .txt 文件,存在于 Hadoop 中目标目录的源和嵌套子目录。

这样的事情可能会将文件从源移动到目标。

hadoop fs -mv /user/source/*.txt /user/target

如何移动超过 2 天的 .txt 文件?

【问题讨论】:

标签: shell hadoop


【解决方案1】:

你可以使用 find commands 漂亮的参数,它允许我们使用一些命令,它是 -exec

find /user/source/*.txt -type f -mtime 2 -exec mv '{}' /user/target \;

但有时这会给文件带来一些问题,因此在这种情况下,您也可以尝试此脚本。您需要从 subdir1/subdir2/ 创建目录树 - 您可以这样做,例如:

find /user/source/*.txt -type f -mtime +2 -print0 | while IFS= read -r -d '' file;do
        dir="${file%/*}"
        mkdir -p ../yourfilearchive/"$dir"
        mv "$file" ../yourhadoopdir/"$file"
    done

此脚本将简单地重新创建您的文件,而不是将它们移动到您的目录中。

如果您想使用 hdfs 自己的命令,这些当然只适用于 2 天以上的 txt 文件,我为此找到了很好的答案。

Get files which are created in last 5 minutes in hadoop using shell script

【讨论】:

  • 寻找HDFS解决方案
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-10
  • 1970-01-01
  • 2015-04-01
  • 1970-01-01
  • 2021-04-22
  • 1970-01-01
相关资源
最近更新 更多