Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hadoop copy a directory?

Tags:

Is there an HDFS API that can copy an entire local directory to the HDFS? I found an API for copying files but is there one for directories?

like image 620
rakeshr Avatar asked Jan 17 '11 19:01

rakeshr


People also ask

How do I copy an entire directory in Hadoop?

You can use the cp command in Hadoop. This command is similar to the Linux cp command, and it is used for copying files from one directory to another directory within the HDFS file system.

How do I copy a directory from local to HDFS?

Step 1: Make a directory in HDFS where you want to copy this file with the below command. Step 2: Use copyFromLocal command as shown below to copy it to HDFS /Hadoop_File directory. Step 3: Check whether the file is copied successfully or not by moving to its directory location with below command.

How do I copy a local file to Hadoop?

In order to copy a file from the local file system to HDFS, use Hadoop fs -put or hdfs dfs -put, on put command, specify the local-file-path where you wanted to copy from and then HDFS-file-path where you wanted to copy to. If the file already exists on HDFS, you will get an error message saying “File already exists”.


1 Answers

Use the Hadoop FS shell. Specifically:

$ hadoop fs -copyFromLocal /path/to/local hdfs:///path/to/hdfs 

If you want to do it programmatically, create two FileSystems (one Local and one HDFS) and use the FileUtil class

like image 110
Spike Gronim Avatar answered Sep 26 '22 00:09

Spike Gronim