问题描述
是否有hdfs命令按照时间戳,升序或降序列出HDFS目录中的文件?默认情况下, hdfs dfs -ls
命令提供未排序的文件列表。
Is there a hdfs command to list files in HDFS directory as per timestamp, ascending or descending? By default, hdfs dfs -ls
command gives unsorted list of files.
当我搜索答案时,我得到的是一个解决方法,即 hdfs dfs -ls / tmp | sort -k6,7
。但有没有更好的方法,内置于 hdfs dfs
命令行?
When I searched for answers what I got was a workaround i.e. hdfs dfs -ls /tmp | sort -k6,7
. But is there any better way, inbuilt in hdfs dfs
commandline?
推荐答案
否,没有其他选项可基于日期时间对文件进行排序。
如果您使用的是hadoop版本< 2.7,你将不得不像你一样使用sort -k6,7:
No, there is no other option to sort the files based on datetime.
If you are using hadoop version < 2.7, you will have to use sort -k6,7 as you are doing:
hdfs dfs -ls /tmp | sort -k6,7
对于hadoop 2.7.x ,有以下选项可用:
And for hadoop 2.7.x ls command , there are following options available :
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.
因此,您可以轻松地对文件进行排序:
So you can easily sort the files:
hdfs dfs -ls -t -R (-r) /tmp
这篇关于是否有一个hdfs命令按照时间戳列出HDFS目录中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!