From 9eb87574a3e10904b1d1fa92bf542b6b0eddcf78 Mon Sep 17 00:00:00 2001 From: Harsh J Date: Wed, 28 Dec 2011 06:48:31 +0000 Subject: [PATCH] HADOOP-7574. Improve FSShell -stat, add user/group elements (XieXianshan via harsh) git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1225114 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-common-project/hadoop-common/CHANGES.txt | 2 ++ .../main/java/org/apache/hadoop/fs/shell/Stat.java | 14 +++++++++++--- .../hadoop-common/src/test/resources/testConf.xml | 4 ++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 5e704f153f..fc7141d1a7 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -77,6 +77,8 @@ Trunk (unreleased changes) HADOOP-7899. Generate proto java files as part of the build. (tucu) + HADOOP-7574. Improve FSShell -stat, add user/group elements (XieXianshan via harsh) + BUGS HADOOP-7851. Configuration.getClasses() never returns the default value. diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Stat.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Stat.java index e8a731a335..d6034390bb 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Stat.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Stat.java @@ -32,9 +32,11 @@ * Print statistics about path in specified format. * Format sequences: * %b: Size of file in blocks + * %g: Group name of owner * %n: Filename * %o: Block size * %r: replication + * %u: User name of owner * %y: UTC date as "yyyy-MM-dd HH:mm:ss" * %Y: Milliseconds since January 1, 1970 UTC */ @@ -50,8 +52,8 @@ public static void registerCommands(CommandFactory factory) { public static final String USAGE = "[format] ..."; public static final String DESCRIPTION = "Print statistics about the file/directory at \n" + - "in the specified format. Format accepts filesize in blocks (%b), filename (%n),\n" + - "block size (%o), replication (%r), modification date (%y, %Y)\n"; + "in the specified format. Format accepts filesize in blocks (%b), group name of owner(%g),\n" + + "filename (%n), block size (%o), replication (%r), user name of owner(%u), modification date (%y, %Y)\n"; protected static final SimpleDateFormat timeFmt; static { @@ -92,6 +94,9 @@ protected void processPath(PathData item) throws IOException { ? "directory" : (stat.isFile() ? "regular file" : "symlink")); break; + case 'g': + buf.append(stat.getGroup()); + break; case 'n': buf.append(item.path.getName()); break; @@ -101,6 +106,9 @@ protected void processPath(PathData item) throws IOException { case 'r': buf.append(stat.getReplication()); break; + case 'u': + buf.append(stat.getOwner()); + break; case 'y': buf.append(timeFmt.format(new Date(stat.getModificationTime()))); break; @@ -118,4 +126,4 @@ protected void processPath(PathData item) throws IOException { } out.println(buf.toString()); } -} \ No newline at end of file +} diff --git a/hadoop-common-project/hadoop-common/src/test/resources/testConf.xml b/hadoop-common-project/hadoop-common/src/test/resources/testConf.xml index b508c304c8..e437cbccad 100644 --- a/hadoop-common-project/hadoop-common/src/test/resources/testConf.xml +++ b/hadoop-common-project/hadoop-common/src/test/resources/testConf.xml @@ -606,11 +606,11 @@ RegexpComparator - ^( |\t)*in the specified format. Format accepts filesize in blocks \(%b\), filename \(%n\),( )* + ^( |\t)*in the specified format. Format accepts filesize in blocks \(%b\), group name of owner\(%g\),( )* RegexpComparator - ^( |\t)*block size \(%o\), replication \(%r\), modification date \(%y, %Y\)( )* + ^( |\t)*filename \(%n\), block size \(%o\), replication \(%r\), user name of owner\(%u\), modification date \(%y, %Y\)( )*