hdfs copy multiple files to same target directory
Asked Answered
D

3

6

I learned that if you want to copy multiple files from one hadoop folder to another hadoop folder you can better create one big 'hdfs dfs -cp' statement with lots of components, instead of creating several hdfs dfs -cp statements. With 'better' I mean that it will improve the overal time it takes to copy files: one command is quicker than several separate -cp commands run after each other.

When I do this and my target directory is the same for all files that I want to copy I get a warning.

I'm executing the following command:

hdfs dfs -cp -f /path1/file1 /pathx/target /path2/file2 /pathx/target /path3/file3 /pathx/target

After executing it I get the following warning returned:

cp: `/pathx/target' to `/pathx/target/target': is a subdirectory of itself

Although I get this weird warning the copy itself succeeds like it should. Is this a bug or am I missing something?

Demetria answered 16/12, 2016 at 13:52 Comment(0)
T
14

Try to use the following syntax:

hadoop fs -cp /path1/file1 /path2/file2 path3/file3 /pathx/target
Tocology answered 16/12, 2016 at 15:35 Comment(1)
ughh that was is. Thanks! I should have check the documentation first... hadoop.apache.org/docs/r2.7.1/hadoop-project-dist/hadoop-common/… so it's hdfs dfs -cp source1 source2 source3 targetDemetria
S
1

Or You could do it like this:

hadoop fs -cp /path1/{file1, file2, file3} /pathx/target

If you want to copy all the files then:

hadoop fs -cp /path1/* /pathx/target
Semite answered 22/11, 2021 at 11:4 Comment(0)
C
0

-cp did not worked for me... I used the following and it worked

hdfs dfs -put /path1/file1 /path2/file2 path3/file3 /pathx/target
Congruence answered 19/5, 2023 at 10:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.