Return-Path: X-Original-To: apmail-hadoop-common-commits-archive@www.apache.org Delivered-To: apmail-hadoop-common-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 24AEC6AB1 for ; Wed, 27 Jul 2011 19:10:25 +0000 (UTC) Received: (qmail 62389 invoked by uid 500); 27 Jul 2011 19:10:24 -0000 Delivered-To: apmail-hadoop-common-commits-archive@hadoop.apache.org Received: (qmail 62274 invoked by uid 500); 27 Jul 2011 19:10:24 -0000 Mailing-List: contact common-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: common-dev@hadoop.apache.org Delivered-To: mailing list common-commits@hadoop.apache.org Received: (qmail 62267 invoked by uid 99); 27 Jul 2011 19:10:23 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 27 Jul 2011 19:10:23 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 27 Jul 2011 19:10:20 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 32BAC2388894; Wed, 27 Jul 2011 19:09:59 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1151594 - in /hadoop/common/trunk/common: CHANGES.txt src/docs/src/documentation/content/xdocs/file_system_shell.xml src/java/org/apache/hadoop/fs/shell/Ls.java src/test/core/org/apache/hadoop/cli/testConf.xml Date: Wed, 27 Jul 2011 19:09:58 -0000 To: common-commits@hadoop.apache.org From: suresh@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110727190959.32BAC2388894@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: suresh Date: Wed Jul 27 19:09:55 2011 New Revision: 1151594 URL: http://svn.apache.org/viewvc?rev=1151594&view=rev Log: HADOOP-7378. Add -d option to ls to not expand directories. Contributed by Daryn Sharp. Modified: hadoop/common/trunk/common/CHANGES.txt hadoop/common/trunk/common/src/docs/src/documentation/content/xdocs/file_system_shell.xml hadoop/common/trunk/common/src/java/org/apache/hadoop/fs/shell/Ls.java hadoop/common/trunk/common/src/test/core/org/apache/hadoop/cli/testConf.xml Modified: hadoop/common/trunk/common/CHANGES.txt URL: http://svn.apache.org/viewvc/hadoop/common/trunk/common/CHANGES.txt?rev=1151594&r1=1151593&r2=1151594&view=diff ============================================================================== --- hadoop/common/trunk/common/CHANGES.txt (original) +++ hadoop/common/trunk/common/CHANGES.txt Wed Jul 27 19:09:55 2011 @@ -289,6 +289,9 @@ Trunk (unreleased changes) HADOOP-7485. Add -h option to ls to list file sizes in human readable format. (XieXianshan via suresh) + HADOOP-7378. Add -d option to ls to not expand directories. + (Daryn Sharp via suresh) + OPTIMIZATIONS HADOOP-7333. Performance improvement in PureJavaCrc32. (Eric Caspole Modified: hadoop/common/trunk/common/src/docs/src/documentation/content/xdocs/file_system_shell.xml URL: http://svn.apache.org/viewvc/hadoop/common/trunk/common/src/docs/src/documentation/content/xdocs/file_system_shell.xml?rev=1151594&r1=1151593&r2=1151594&view=diff ============================================================================== --- hadoop/common/trunk/common/src/docs/src/documentation/content/xdocs/file_system_shell.xml (original) +++ hadoop/common/trunk/common/src/docs/src/documentation/content/xdocs/file_system_shell.xml Wed Jul 27 19:09:55 2011 @@ -273,7 +273,7 @@
ls

- Usage: hdfs dfs -ls [-R] [-h] <args> + Usage: hdfs dfs -ls [-d] [-h] [-R] <args>

For a file returns stat on the file with the following format:

@@ -284,10 +284,11 @@ permissions userid groupid modification_date modification_time dirname

Options:

-
    -
  • The -R option will list subdirectories recursively.
  • -
  • The -h option will format file sizes in a "human-readable" fashion (e.g 64.0m instead of 67108864)
  • -
+
    +
  • -d Directories are listed as plain files
  • +
  • -h Format file sizes in a "human-readable" fashion (e.g 64.0m instead of 67108864)
  • +
  • -R Recursively list subdirectories encountered
  • +

Example:

hdfs dfs -ls /user/hadoop/file1 Modified: hadoop/common/trunk/common/src/java/org/apache/hadoop/fs/shell/Ls.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/common/src/java/org/apache/hadoop/fs/shell/Ls.java?rev=1151594&r1=1151593&r2=1151594&view=diff ============================================================================== --- hadoop/common/trunk/common/src/java/org/apache/hadoop/fs/shell/Ls.java (original) +++ hadoop/common/trunk/common/src/java/org/apache/hadoop/fs/shell/Ls.java Wed Jul 27 19:09:55 2011 @@ -42,7 +42,7 @@ class Ls extends FsCommand { } public static final String NAME = "ls"; - public static final String USAGE = "[-R] [-h] [ ...]"; + public static final String USAGE = "[-d] [-h] [-R] [ ...]"; public static final String DESCRIPTION = "List the contents that match the specified file pattern. If\n" + "path is not specified, the contents of /user/\n" + @@ -52,15 +52,17 @@ class Ls extends FsCommand { "\tfileName(full path) size \n" + "where n is the number of replicas specified for the file \n" + "and size is the size of the file, in bytes.\n" + - " -R Recursively list the contents of directories.\n" + + " -d Directories are listed as plain files.\n" + " -h Formats the sizes of files in a human-readable fashion\n" + - " rather than of bytes.\n\n"; + " rather than a number of bytes.\n" + + " -R Recursively list the contents of directories."; protected static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); protected int maxRepl = 3, maxLen = 10, maxOwner = 0, maxGroup = 0; protected String lineFormat; + protected boolean dirRecurse; protected boolean humanReadable = false; protected String formatSize(long size) { @@ -72,22 +74,27 @@ class Ls extends FsCommand { @Override protected void processOptions(LinkedList args) throws IOException { - CommandFormat cf = new CommandFormat(0, Integer.MAX_VALUE, "R", "h"); + CommandFormat cf = new CommandFormat(0, Integer.MAX_VALUE, "d", "h", "R"); cf.parse(args); - setRecursive(cf.getOpt("R")); + dirRecurse = !cf.getOpt("d"); + setRecursive(cf.getOpt("R") && dirRecurse); humanReadable = cf.getOpt("h"); if (args.isEmpty()) args.add(Path.CUR_DIR); } @Override - protected void processPaths(PathData parent, PathData ... items) - throws IOException { + protected void processPathArgument(PathData item) throws IOException { // implicitly recurse once for cmdline directories - if (parent == null && items[0].stat.isDirectory()) { - recursePath(items[0]); - return; + if (dirRecurse && item.stat.isDirectory()) { + recursePath(item); + } else { + super.processPathArgument(item); } + } + @Override + protected void processPaths(PathData parent, PathData ... items) + throws IOException { if (!isRecursive() && items.length != 0) { out.println("Found " + items.length + " items"); } Modified: hadoop/common/trunk/common/src/test/core/org/apache/hadoop/cli/testConf.xml URL: http://svn.apache.org/viewvc/hadoop/common/trunk/common/src/test/core/org/apache/hadoop/cli/testConf.xml?rev=1151594&r1=1151593&r2=1151594&view=diff ============================================================================== --- hadoop/common/trunk/common/src/test/core/org/apache/hadoop/cli/testConf.xml (original) +++ hadoop/common/trunk/common/src/test/core/org/apache/hadoop/cli/testConf.xml Wed Jul 27 19:09:55 2011 @@ -54,7 +54,7 @@ RegexpComparator - ^-ls \[-R\] \[-h\] \[<path> \.\.\.\]:( |\t)*List the contents that match the specified file pattern. If( )* + ^-ls \[-d\] \[-h\] \[-R\] \[<path> \.\.\.\]:( |\t)*List the contents that match the specified file pattern. If( )* RegexpComparator @@ -90,15 +90,19 @@ RegexpComparator - ^( |\t)*-R Recursively list the contents of directories.( )* + ^( |\t)*-d\s+Directories are listed as plain files\. RegexpComparator - ^( |\t)*-h Formats the sizes of files in a human-readable fashion( )* + ^( |\t)*-h\s+Formats the sizes of files in a human-readable fashion( )* RegexpComparator - ^( |\t)*rather than a number of bytes.( )* + ^( |\t)*rather than a number of bytes\.( )* + + + RegexpComparator + ^( |\t)*-R\s+Recursively list the contents of directories\.