如何在hadoop中根据出生时间移动文件

wtzytmuj  于 2021-05-29  发布在  Hadoop
关注(0)|答案(1)|浏览(437)

我在一个文件夹中有大约200k个文件,我想根据出生时间(创建时间)来组织它们。我写了下面的脚本,但太慢了。我想改进一下。我该怎么做?

  1. # !/usr/bin/env bash
  2. echo Input directory is $1
  3. input_directory=$1
  4. ## Find those files that are older than a month
  5. inputfiles=$(hadoop fs -ls $input_directory | sed '1d;s/ */ /g' | cut -d\ -f8)
  6. for filename in $inputfiles
  7. do
  8. echo processing $filename
  9. hadoop fs -test -d $filename
  10. lastcommand=$?
  11. if [ "$lastcommand" == "1" ];then
  12. year=$(date -d "`hadoop fs -stat $filename`" +%Y)
  13. month=$(date -d "`hadoop fs -stat $filename`" +%m)
  14. hadoop fs -test -d $input_directory/$year-$month
  15. lastcommand2=$?
  16. [[ "$lastcommand2" == "1" ]] && hadoop fs -mkdir -p $input_directory/$year-$month;
  17. hadoop fs -mv $filename $input_directory/$year-$month/
  18. else
  19. echo not a file
  20. fi
  21. done
im9ewurl

im9ewurl1#

我能够使用hadoop文件系统重命名命令来移动苍蝇,而且效果很好。把时间从小时缩短到一分钟。谢谢您

相关问题