HDFS文件时间戳

chh*_*rma 5 datetime hadoop hdfs

我想在 hdfs 上获取文件的 last_modification 时间。我检查了 HDFS shell 指南,但没有得到任何可用的相关命令。

Hadoop 版本为 2.4.0。谁能建议我如何获得 hdfs 文件的 last_modification 时间?

提前致谢

Sha*_*shi 5

您可以从 hadoop ls 命令检索时间戳并使用 awk 解析它。文件/目录时间戳有模式。对于文件来说是

permissions number_of_replicas userid groupid filesize modification_date modification_time filename 
Run Code Online (Sandbox Code Playgroud)

目录是

permissions userid groupid modification_date modification_time dirname
Run Code Online (Sandbox Code Playgroud)

文件的第六和第七字段为您提供修改日期和时间。您可以使用下面的示例来检索这些信息。

hadoop fs -ls /textfile | awk '{timestamp= $6  "  "  $7;print timestamp}'
Run Code Online (Sandbox Code Playgroud)

请参阅 ls 命令的文档。

http://hadoop.apache.org/docs/r2.7.0/hadoop-project-dist/hadoop-common/FileSystemShell.html 希望这会有所帮助。

  • 如果你想以编程方式解析该日期时间,你可能会更好地使用`hadoop fs -stat`http://hadoop.apache.org/docs/r2.7.0/hadoop-project-dist/hadoop-common/FileSystemShell.html #统计 (2认同)