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.
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?
Best Answer
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:
And for hadoop 2.7.x ls command , there are following options available :
So you can easily sort the files: