Section 5:42. Copying or Moving Files from one HDFS location to other HDFS location

We can also copy files within HDFS using commands like cp and mv.

  • hadoop fs -cp  to copy files from one HDFS location to another HDFS location
  • hadoop fs -mv  to move files from one HDFS location to another HDFS location
  • mv is faster than cp as mv deals with only metadata whereas cp has to copy all the blocks.
  • If you have to rename or move the files make sure to run hadoop fs -mv

The “hdfs cp” command allows you to copy files from one location to another within HDFS, or from the local file system to HDFS. The basic syntax for the “hdfs cp” command is as follows:

hdfs dfs -cp <source> <destination>

Here, <source> is the path of the file or directory that you want to copy, and <destination> is the location where you want to copy the file or directory to.

The “hdfs mv” command allows you to move files from one location to another within HDFS, or from HDFS to the local file system. The basic syntax for the “hdfs mv” command is as follows:

hdfs dfs -mv <source> <destination>

Note that “hdfs mv” is actually equivalent to renaming the file or directory in HDFS. If you want to move the file or directory to a different directory within HDFS, you need to specify the full path of the destination directory.

Share this post