是否有hdfs命令根据时间戳列出hdfs目录中的文件

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

是否有hdfs命令按时间戳升序或降序列出hdfs目录中的文件?默认情况下, hdfs dfs -ls 命令给出未排序的文件列表。
当我寻找答案时,我得到的是一个解决办法,即。 hdfs dfs -ls /tmp | sort -k6,7 . 但是有没有更好的方法,内在的 hdfs dfs 命令行?

wtzytmuj

wtzytmuj1#

不,没有其他选项可以根据日期时间对文件进行排序。
如果您使用的是hadoop版本<2.7,则必须使用sort-k6,7:

hdfs dfs -ls /tmp | sort -k6,7

对于hadoop 2.7.x ls命令,有以下可用选项:

Usage: hadoop fs -ls [-d] [-h] [-R] [-t] [-S] [-r] [-u] <args>

Options:
-d: Directories are listed as plain files.
-h: Format file sizes in a human-readable fashion (eg 64.0m instead of 67108864).
-R: Recursively list subdirectories encountered.
-t: Sort output by modification time (most recent first).
-S: Sort output by file size.
-r: Reverse the sort order.
-u: Use access time rather than modification time for display and sorting.

因此,您可以轻松地对文件进行排序:

hdfs dfs -ls -t -R (-r) /tmp

相关问题