获取HDFS中的最新更新文件 [英] Get the last updated file in HDFS

查看:201
本文介绍了获取HDFS中的最新更新文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我的HDFS目录中找到最新的更新文件。代码应该基本上循环访问目录和子目录,并获取最新的文件路径和文件名。我能够在本地文件系统中获取最新文件,但不知道如何为HDFS文件系统执行此操作。



find / tmp / sdsa -type f -print0 | xargs -0 stat --format'%Y:%y%n'| sort -nr | cut -d:-f2- |头



以上代码适用于本地文件系统。我可以从HDFS获取日期,时间和文件名,但是如何使用这3个参数获取最新文件?



这是我试过的代码:



hadoop fs -ls -R / tmp / apps | awk -F'{print $ 6$ 7$ 8}'



任何帮助将不胜感激。 / p>

在此先感谢。

解决方案

/ p>

hadoop fs -ls -R / tmp / app | awk -F'{print $ 6$ 7$ 8}'| sort -nr |头-1 | cut -d-f3



输出是整个文件路径。


I want the latest updated file from one of my HDFS directories. The code should basically loop through the directories and sub directories and the get the latest file path with the file name.I was able to get the latest file in local file system but not sure how to do it for HDFS one.

find /tmp/sdsa -type f -print0 | xargs -0 stat --format '%Y :%y %n' | sort -nr | cut -d: -f2- | head

The above code is working for local file system. I am able to get the date , time and file name from HDFS, but how do I get the latest file using these 3 parameters?

this is the code I tried:

hadoop fs -ls -R /tmp/apps | awk -F" " '{print $6" "$7" "$8}'

Any help will be appreciated.

Thanks in advance.

解决方案

This one worked for me:

hadoop fs -ls -R /tmp/app | awk -F" " '{print $6" "$7" "$8}' | sort -nr | head -1 | cut -d" " -f3

The output is the entire file path.

这篇关于获取HDFS中的最新更新文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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