Wednesday 23 March 2022

Hadoop: copyFromLocal: Copy folder content from local file system to hdfs

“copyFromLocal” command is used to Copy file from local file system to HDFS.

 

Usage

hadoop fs [generic options] -copyFromLocal [-f] [-p] [-l] <localsrc> ... <dst>

Options:
   The -f option will overwrite the destination if it already exists.

Example

hadoop fs -copyFromLocal {myLocalFolder} {hdfcLocationToCopy}

To demonstrate the example, I created a directory ‘testData’ with three files.

$ls /home/cloudera/Desktop/testData
a.txt  b.txt  c.txt

I would like to copy the folder ‘testData’ to ‘/user/cloudera/demo4’ folder, which is not exist.

$hadoop fs -ls /user/cloudera
Found 3 items
drwxr-xr-x   - cloudera cloudera          0 2022-03-23 07:17 /user/cloudera/demo1
drwxr-xr-x   - cloudera cloudera          0 2022-03-23 07:03 /user/cloudera/demo2
drwxr-xr-x   - cloudera cloudera          0 2022-03-23 08:06 /user/cloudera/putDemo

Let me copy the folder by executing below command.

hadoop fs -copyFromLocal /home/cloudera/Desktop/testData /user/cloudera/demo4

$hadoop fs -copyFromLocal /home/cloudera/Desktop/testData /user/cloudera/demo4
$
$hadoop fs -ls /user/cloudera
Found 4 items
drwxr-xr-x   - cloudera cloudera          0 2022-03-23 07:17 /user/cloudera/demo1
drwxr-xr-x   - cloudera cloudera          0 2022-03-23 07:03 /user/cloudera/demo2
drwxr-xr-x   - cloudera cloudera          0 2022-03-23 09:03 /user/cloudera/demo4
drwxr-xr-x   - cloudera cloudera          0 2022-03-23 08:06 /user/cloudera/putDemo
$
$hadoop fs -ls /user/cloudera/demo4
Found 3 items
-rw-r--r--   1 cloudera cloudera          2 2022-03-23 09:03 /user/cloudera/demo4/a.txt
-rw-r--r--   1 cloudera cloudera         35 2022-03-23 09:03 /user/cloudera/demo4/b.txt
-rw-r--r--   1 cloudera cloudera         55 2022-03-23 09:03 /user/cloudera/demo4/c.txt

 


 



 

 

Previous                                                 Next                                                 Home

No comments:

Post a Comment