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
This commit is contained in:
Harsh J 2011-12-28 06:48:31 +00:00
parent fcbad14a3d
commit 9eb87574a3
3 changed files with 15 additions and 5 deletions

View File

@ -77,6 +77,8 @@ Trunk (unreleased changes)
HADOOP-7899. Generate proto java files as part of the build. (tucu) 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 BUGS
HADOOP-7851. Configuration.getClasses() never returns the default value. HADOOP-7851. Configuration.getClasses() never returns the default value.

View File

@ -32,9 +32,11 @@
* Print statistics about path in specified format. * Print statistics about path in specified format.
* Format sequences: * Format sequences:
* %b: Size of file in blocks * %b: Size of file in blocks
* %g: Group name of owner
* %n: Filename * %n: Filename
* %o: Block size * %o: Block size
* %r: replication * %r: replication
* %u: User name of owner
* %y: UTC date as "yyyy-MM-dd HH:mm:ss" * %y: UTC date as "yyyy-MM-dd HH:mm:ss"
* %Y: Milliseconds since January 1, 1970 UTC * %Y: Milliseconds since January 1, 1970 UTC
*/ */
@ -50,8 +52,8 @@ public static void registerCommands(CommandFactory factory) {
public static final String USAGE = "[format] <path> ..."; public static final String USAGE = "[format] <path> ...";
public static final String DESCRIPTION = public static final String DESCRIPTION =
"Print statistics about the file/directory at <path>\n" + "Print statistics about the file/directory at <path>\n" +
"in the specified format. Format accepts filesize in blocks (%b), filename (%n),\n" + "in the specified format. Format accepts filesize in blocks (%b), group name of owner(%g),\n" +
"block size (%o), replication (%r), modification date (%y, %Y)\n"; "filename (%n), block size (%o), replication (%r), user name of owner(%u), modification date (%y, %Y)\n";
protected static final SimpleDateFormat timeFmt; protected static final SimpleDateFormat timeFmt;
static { static {
@ -92,6 +94,9 @@ protected void processPath(PathData item) throws IOException {
? "directory" ? "directory"
: (stat.isFile() ? "regular file" : "symlink")); : (stat.isFile() ? "regular file" : "symlink"));
break; break;
case 'g':
buf.append(stat.getGroup());
break;
case 'n': case 'n':
buf.append(item.path.getName()); buf.append(item.path.getName());
break; break;
@ -101,6 +106,9 @@ protected void processPath(PathData item) throws IOException {
case 'r': case 'r':
buf.append(stat.getReplication()); buf.append(stat.getReplication());
break; break;
case 'u':
buf.append(stat.getOwner());
break;
case 'y': case 'y':
buf.append(timeFmt.format(new Date(stat.getModificationTime()))); buf.append(timeFmt.format(new Date(stat.getModificationTime())));
break; break;
@ -118,4 +126,4 @@ protected void processPath(PathData item) throws IOException {
} }
out.println(buf.toString()); out.println(buf.toString());
} }
} }

View File

@ -606,11 +606,11 @@
</comparator> </comparator>
<comparator> <comparator>
<type>RegexpComparator</type> <type>RegexpComparator</type>
<expected-output>^( |\t)*in the specified format. Format accepts filesize in blocks \(%b\), filename \(%n\),( )*</expected-output> <expected-output>^( |\t)*in the specified format. Format accepts filesize in blocks \(%b\), group name of owner\(%g\),( )*</expected-output>
</comparator> </comparator>
<comparator> <comparator>
<type>RegexpComparator</type> <type>RegexpComparator</type>
<expected-output>^( |\t)*block size \(%o\), replication \(%r\), modification date \(%y, %Y\)( )*</expected-output> <expected-output>^( |\t)*filename \(%n\), block size \(%o\), replication \(%r\), user name of owner\(%u\), modification date \(%y, %Y\)( )*</expected-output>
</comparator> </comparator>
</comparators> </comparators>
</test> </test>