Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/hadoop/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unix hadoop命令从hadoop中的目录获取最新的子目录名_Unix_Hadoop - Fatal编程技术网

Unix hadoop命令从hadoop中的目录获取最新的子目录名

Unix hadoop命令从hadoop中的目录获取最新的子目录名,unix,hadoop,Unix,Hadoop,如何在hadoop中找到在目录中创建的最新子目录? e、 g在hadoop中,如果我有一个名为mgm的目录,它有两个子目录1和2,如下所示: /user/mgm/1 /user/mgm/2 我想知道1或2中的哪一个是最先创建的 hadoop fs -ls -t /user/mgm/ | head -1 他不适合我。它说,非法选项-thdfs dfs-ls的-t选项是针对ApacheHadoop2.8.0的新功能,该功能尚未发布。这一点在JIRA问题中得到跟踪。我不确定为什么该选项在文档中已

如何在hadoop中找到在目录中创建的最新子目录? e、 g在hadoop中,如果我有一个名为mgm的目录,它有两个子目录1和2,如下所示:

/user/mgm/1
/user/mgm/2
我想知道1或2中的哪一个是最先创建的

hadoop fs -ls -t /user/mgm/ | head -1 
他不适合我。它说,非法选项-t

hdfs dfs-ls的-t选项是针对ApacheHadoop2.8.0的新功能,该功能尚未发布。这一点在JIRA问题中得到跟踪。我不确定为什么该选项在文档中已经可见

同时,另一个选项是使用包含修改时间的格式字符串的命令。下面是一个示例,演示如何使用hdfs dfs-stat将dir2标识为具有最新修改时间的子目录

> hdfs dfs -mkdir /user/mgm/dir1

> hdfs dfs -mkdir /user/mgm/dir2

> hdfs dfs -ls /user/mgm
Found 2 items
drwxr-xr-x   - chris supergroup          0 2015-12-31 14:38 /user/mgm/dir1
drwxr-xr-x   - chris supergroup          0 2015-12-31 14:38 /user/mgm/dir2

> hdfs dfs -help stat
-stat [format] <path> ... :
  Print statistics about the file/directory at <path>
  in the specified format. Format accepts filesize in
  blocks (%b), type (%F), group name of owner (%g),
  name (%n), block size (%o), replication (%r), user name
  of owner (%u), modification date (%y, %Y).
  %y shows UTC date as "yyyy-MM-dd HH:mm:ss" and
  %Y shows milliseconds since January 1, 1970 UTC.
  If the format is not specified, %y is used by default.

> hdfs dfs -stat '%y    %n' /user/mgm/*
2015-12-31 22:38:16    dir1
2015-12-31 22:38:19    dir2

> hdfs dfs -stat '%Y    %n' /user/mgm/*
1451601496198    dir1
1451601499150    dir2

> hdfs dfs -stat '%Y    %n' /user/mgm/* | sort -nr | head -1 | awk '{ print $NF }'
dir2
如何在hadoop中找到在目录中创建的最新子目录

请记住,所有这些特性都是指修改时间,而不是创建时间。修改时间可以随着目录内容的更改而更新。如果你真的非常需要创建时间,那么请注意这一点。没有选项可用于将创建时间作为与修改时间分开跟踪的值来获取可见性。

hdfs dfs-ls的-t选项是针对Apache Hadoop 2.8.0的新功能,该功能尚未发布。这一点在JIRA问题中得到跟踪。我不确定为什么该选项在文档中已经可见

> hdfs dfs -mkdir /user/mgm/dir1

> hdfs dfs -mkdir /user/mgm/dir2

> hdfs dfs -ls /user/mgm
Found 2 items
drwxr-xr-x   - chris supergroup          0 2015-12-31 14:38 /user/mgm/dir1
drwxr-xr-x   - chris supergroup          0 2015-12-31 14:38 /user/mgm/dir2

> hdfs dfs -help stat
-stat [format] <path> ... :
  Print statistics about the file/directory at <path>
  in the specified format. Format accepts filesize in
  blocks (%b), type (%F), group name of owner (%g),
  name (%n), block size (%o), replication (%r), user name
  of owner (%u), modification date (%y, %Y).
  %y shows UTC date as "yyyy-MM-dd HH:mm:ss" and
  %Y shows milliseconds since January 1, 1970 UTC.
  If the format is not specified, %y is used by default.

> hdfs dfs -stat '%y    %n' /user/mgm/*
2015-12-31 22:38:16    dir1
2015-12-31 22:38:19    dir2

> hdfs dfs -stat '%Y    %n' /user/mgm/*
1451601496198    dir1
1451601499150    dir2

> hdfs dfs -stat '%Y    %n' /user/mgm/* | sort -nr | head -1 | awk '{ print $NF }'
dir2
同时,另一个选项是使用包含修改时间的格式字符串的命令。下面是一个示例,演示如何使用hdfs dfs-stat将dir2标识为具有最新修改时间的子目录

> hdfs dfs -mkdir /user/mgm/dir1

> hdfs dfs -mkdir /user/mgm/dir2

> hdfs dfs -ls /user/mgm
Found 2 items
drwxr-xr-x   - chris supergroup          0 2015-12-31 14:38 /user/mgm/dir1
drwxr-xr-x   - chris supergroup          0 2015-12-31 14:38 /user/mgm/dir2

> hdfs dfs -help stat
-stat [format] <path> ... :
  Print statistics about the file/directory at <path>
  in the specified format. Format accepts filesize in
  blocks (%b), type (%F), group name of owner (%g),
  name (%n), block size (%o), replication (%r), user name
  of owner (%u), modification date (%y, %Y).
  %y shows UTC date as "yyyy-MM-dd HH:mm:ss" and
  %Y shows milliseconds since January 1, 1970 UTC.
  If the format is not specified, %y is used by default.

> hdfs dfs -stat '%y    %n' /user/mgm/*
2015-12-31 22:38:16    dir1
2015-12-31 22:38:19    dir2

> hdfs dfs -stat '%Y    %n' /user/mgm/*
1451601496198    dir1
1451601499150    dir2

> hdfs dfs -stat '%Y    %n' /user/mgm/* | sort -nr | head -1 | awk '{ print $NF }'
dir2
如何在hadoop中找到在目录中创建的最新子目录


请记住,所有这些特性都是指修改时间,而不是创建时间。修改时间可以随着目录内容的更改而更新。如果你真的非常需要创建时间,那么请注意这一点。没有选项可以将创建时间作为一个与修改时间分开跟踪的值来获取可见性。

您有什么版本的hadoop?-t标志是否可以更新hadoop二进制文件?您有什么版本的hadoop?-t标志你能更新你的hadoop二进制文件吗?@Monica,我很高兴听到它!:-如果这是有益的,那么请考虑将答案标记为接受。完全相同的问题,用我的最后命令解决我的情况。非常感谢@莫妮卡,听到这个消息我很高兴如果这是有益的,那么请考虑将答案标记为接受。完全相同的问题,用我的最后命令解决我的情况。非常感谢!
> hdfs dfs -mkdir /user/mgm/dir1

> hdfs dfs -mkdir /user/mgm/dir2

> hdfs dfs -ls /user/mgm
Found 2 items
drwxr-xr-x   - chris supergroup          0 2015-12-31 14:38 /user/mgm/dir1
drwxr-xr-x   - chris supergroup          0 2015-12-31 14:38 /user/mgm/dir2

> hdfs dfs -help stat
-stat [format] <path> ... :
  Print statistics about the file/directory at <path>
  in the specified format. Format accepts filesize in
  blocks (%b), type (%F), group name of owner (%g),
  name (%n), block size (%o), replication (%r), user name
  of owner (%u), modification date (%y, %Y).
  %y shows UTC date as "yyyy-MM-dd HH:mm:ss" and
  %Y shows milliseconds since January 1, 1970 UTC.
  If the format is not specified, %y is used by default.

> hdfs dfs -stat '%y    %n' /user/mgm/*
2015-12-31 22:38:16    dir1
2015-12-31 22:38:19    dir2

> hdfs dfs -stat '%Y    %n' /user/mgm/*
1451601496198    dir1
1451601499150    dir2

> hdfs dfs -stat '%Y    %n' /user/mgm/* | sort -nr | head -1 | awk '{ print $NF }'
dir2