You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by cu...@apache.org on 2006/02/10 18:37:00 UTC

svn commit: r376774 - /lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DFSShell.java

Author: cutting
Date: Fri Feb 10 09:36:56 2006
New Revision: 376774

URL: http://svn.apache.org/viewcvs?rev=376774&view=rev
Log:
Fix HADOOP-30: add -lsr and -cat commands to DFSShell.  Contributed by Michel Tourn.

Modified:
    lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DFSShell.java

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DFSShell.java
URL: http://svn.apache.org/viewcvs/lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DFSShell.java?rev=376774&r1=376773&r2=376774&view=diff
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DFSShell.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DFSShell.java Fri Feb 10 09:36:56 2006
@@ -65,18 +65,37 @@
         System.err.println("Option '-moveToLocal' is not implemented yet.");
     }
 
+    void cat(String srcf) throws IOException {
+      FSDataInputStream in = null;
+      try {
+        in = fs.open(new File(srcf));
+        DataInputStream din = new DataInputStream(new BufferedInputStream(in));
+        String line;
+        while((line = din.readLine()) != null) {
+          System.out.println(line);      
+        }
+      } finally {
+        in.close();
+      }
+    }
+
     /**
      * Get a listing of all files in DFS at the indicated name
      */
-    public void ls(String src) throws IOException {
+    public void ls(String src, boolean recursive) throws IOException {
         File items[] = fs.listFiles(new File(src));
         if (items == null) {
             System.out.println("Could not get listing for " + src);
         } else {
-            System.out.println("Found " + items.length + " items");
+            if(!recursive) {
+            	System.out.println("Found " + items.length + " items");
+            }
             for (int i = 0; i < items.length; i++) {
                 File cur = items[i];
                 System.out.println(cur.getPath() + "\t" + (cur.isDirectory() ? "<dir>" : ("" + cur.length())));
+                if(recursive && cur.isDirectory()) {
+									 ls(cur.getPath(), recursive);
+                }
             }
         }
     }
@@ -213,9 +232,9 @@
     public static void main(String argv[]) throws IOException {
         if (argv.length < 1) {
             System.out.println("Usage: java DFSShell [-local | -dfs <namenode:port>]" +
-                    " [-ls <path>] [-du <path>] [-mv <src> <dst>] [-cp <src> <dst>] [-rm <src>]" +
+                    " [-ls <path>] [-lsr <path>] [-du <path>] [-mv <src> <dst>] [-cp <src> <dst>] [-rm <src>]" +
                     " [-put <localsrc> <dst>] [-copyFromLocal <localsrc> <dst>] [-moveFromLocal <localsrc> <dst>]" + 
-                    " [-get <src> <localdst>] [-copyToLocal <src> <localdst>] [-moveToLocal <src> <localdst>]" +
+                    " [-get <src> <localdst>] [-cat <src>] [-copyToLocal <src> <localdst>] [-moveToLocal <src> <localdst>]" +
                     " [-mkdir <path>] [-report]");
             return;
         }
@@ -233,11 +252,16 @@
                 tc.moveFromLocal(new File(argv[i++]), argv[i++]);
             } else if ("-get".equals(cmd) || "-copyToLocal".equals(cmd)) {
                 tc.copyToLocal(argv[i++], new File(argv[i++]));
+            } else if ("-cat".equals(cmd)) {
+                tc.cat(argv[i++]);
             } else if ("-moveToLocal".equals(cmd)) {
                 tc.moveToLocal(argv[i++], new File(argv[i++]));
             } else if ("-ls".equals(cmd)) {
                 String arg = i < argv.length ? argv[i++] : "";
-                tc.ls(arg);
+                tc.ls(arg, false);
+            } else if ("-lsr".equals(cmd)) {
+                String arg = i < argv.length ? argv[i++] : "";
+                tc.ls(arg, true);
             } else if ("-mv".equals(cmd)) {
                 tc.rename(argv[i++], argv[i++]);
             } else if ("-cp".equals(cmd)) {