Saturday, 2 January 2016

Hadoop: cp: copy files from one HDFS locaiton to other HDFS location

“cp” command is used to copy multiple files to HDFS directory. By using cp you can’t copy files from local file system. cp is used when you wish to copy data from one HDFS location to another HDFS location. To copy data from local file system to HDFS you can use either put or copyFromLocal.

Usage:
hadoop fs [generic options] -cp [-f] [-p | -p[topax]] <src> ... <dst>
 
Example
hadoop fs -cp /user/cloudera/demo1/a.txt /user/cloudera/demo1/info.txt /user/cloudera/demo3
 
Above command copy the files a.txt, info.txt to the folder demo3.

$hadoop fs -ls /user/cloudera/demo1
Found 6 items
-rw-r--r--   1 cloudera cloudera          2 2022-03-22 23:58 /user/cloudera/demo1/a.txt
-rw-r--r--   1 cloudera cloudera    6166736 2022-03-22 23:57 /user/cloudera/demo1/atlas.docx
-rw-r--r--   1 cloudera cloudera    9147128 2022-03-22 23:57 /user/cloudera/demo1/atlasClient.docx
-rw-r--r--   1 cloudera cloudera    6988969 2022-03-22 23:58 /user/cloudera/demo1/gradle.docx
-rw-r--r--   1 cloudera cloudera       2539 2022-03-23 21:10 /user/cloudera/demo1/info.txt
-rw-r--r--   1 cloudera cloudera    8986359 2022-03-22 23:58 /user/cloudera/demo1/maven.docx
$
$hadoop fs -ls /user/cloudera/demo3
$
$hadoop fs -cp /user/cloudera/demo1/a.txt /user/cloudera/demo1/info.txt /user/cloudera/demo3
$
$hadoop fs -ls /user/cloudera/demo3
Found 2 items
-rw-r--r--   1 cloudera cloudera          2 2022-03-23 21:28 /user/cloudera/demo3/a.txt
-rw-r--r--   1 cloudera cloudera       2539 2022-03-23 21:28 /user/cloudera/demo3/info.txt
 
Previous                                                 Next                                                 Home

No comments:

Post a Comment