是否有hdfs命令按时间戳,升序或降序列出HDFS目录中的文件?默认情况下,hdfs dfs -lscommand提供未排序的文件列表.
当我搜索答案时,我得到的是一种解决方法,即hdfs dfs -ls /tmp | sort -k6,7.但有没有更好的方法,内置hdfs dfs命令行?
Nis*_*yal 40
不,没有其他选项可以根据日期时间对文件进行排序.
如果您使用hadoop版本<2.7,则必须使用sort -k6,7:
hdfs dfs -ls /tmp | sort -k6,7
Run Code Online (Sandbox Code Playgroud)
对于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.
Run Code Online (Sandbox Code Playgroud)
所以你可以轻松地对文件进行排序:
hdfs dfs -ls -t -R (-r) /tmp
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
68487 次 |
| 最近记录: |