如何在hadoop中根据出生时间移动文件
how to move files based on birth time in hadoop
我在一个文件夹中有大约 200k 个文件,我想根据出生时间(创建时间)来组织它们。我写了下面的脚本,但它太慢了。我想改进它。我该怎么做?
#!/usr/bin/env bash
echo Input directory is
input_directory=
## Find those files that are older than a month
inputfiles=$(hadoop fs -ls $input_directory | sed '1d;s/ */ /g' | cut -d\ -f8)
for filename in $inputfiles
do
echo processing $filename
hadoop fs -test -d $filename
lastcommand=$?
if [ "$lastcommand" == "1" ];then
year=$(date -d "`hadoop fs -stat $filename`" +%Y)
month=$(date -d "`hadoop fs -stat $filename`" +%m)
hadoop fs -test -d $input_directory/$year-$month
lastcommand2=$?
[[ "$lastcommand2" == "1" ]] && hadoop fs -mkdir -p $input_directory/$year-$month;
hadoop fs -mv $filename $input_directory/$year-$month/
else
echo not a file
fi
done
我能够使用 hadoop 文件系统重命名命令来移动苍蝇,而且效果很好。把时间从几小时缩短到一分钟。谢谢
我在一个文件夹中有大约 200k 个文件,我想根据出生时间(创建时间)来组织它们。我写了下面的脚本,但它太慢了。我想改进它。我该怎么做?
#!/usr/bin/env bash
echo Input directory is
input_directory=
## Find those files that are older than a month
inputfiles=$(hadoop fs -ls $input_directory | sed '1d;s/ */ /g' | cut -d\ -f8)
for filename in $inputfiles
do
echo processing $filename
hadoop fs -test -d $filename
lastcommand=$?
if [ "$lastcommand" == "1" ];then
year=$(date -d "`hadoop fs -stat $filename`" +%Y)
month=$(date -d "`hadoop fs -stat $filename`" +%m)
hadoop fs -test -d $input_directory/$year-$month
lastcommand2=$?
[[ "$lastcommand2" == "1" ]] && hadoop fs -mkdir -p $input_directory/$year-$month;
hadoop fs -mv $filename $input_directory/$year-$month/
else
echo not a file
fi
done
我能够使用 hadoop 文件系统重命名命令来移动苍蝇,而且效果很好。把时间从几小时缩短到一分钟。谢谢