Open In App

Hadoop - copyFromLocal Command

Last Updated : 04 Aug, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

The Hadoop copyFromLocal command copies files from the local file system (Linux/Windows/Mac) into HDFS for storage or processing. It is commonly used to upload datasets, logs or configuration files. The -f option forces overwriting of existing files in HDFS, similar to deleting the old file before copying. Without -f, Hadoop throws an error if the file already exists.

Syntax

hdfs dfs -copyFromLocal [-f] <source_path1> <source_path2> ... <destination>

Parameters:

  • source_path: The file(s) in your local file system. Multiple files can be specified.
  • destination: Must be a directory in HDFS where files will be copied.
  • -f: Optional switch to force overwrite if the file already exists.

Note: The copyFromLocal command is identical to -put and can be used with either hdfs dfs or hadoop fs. The last argument always specifies the destination path in HDFS.

Steps to execute copyFromLocal Command

Let's see the current view of my Root directory in HDFS. 

Step 1: Make a directory in HDFS where you want to copy this file with the below command. 

hdfs dfs -mkdir /Hadoop_File

making a directory in HDFSshowing the directory of HDFS

Step 2: Use copyFromLocal command as shown below to copy it to HDFS /Hadoop_File directory. 

hdfs dfs -copyFromLocal /home/dikshant/Documents/hadoop_file/Salaries.csv /Hadoop_File

using copyFromLocal Command in Hadoop

Step 3: Check whether the file is copied successfully or not by moving to its directory location with below command. 

hdfs dfs -ls /Hadoop_File

checking file is copied or not - 1checking file is copied or not - 2

Overwriting or Updating the File In HDFS with -f switch

From below Image, you can observe that copyFromLocal command itself does not copy the same name file at the same location. it says that the file already exists. 

Overwriting or Updating the File In HDFS with -f switch - 1

To update the content of the file or to Overwrite it, you should use -f switch as shown below.

hdfs dfs -copyFromLocal -f /home/dikshant/Documents/hadoop_file/Salaries.csv /Hadoop_File

Overwriting or Updating the File In HDFS with -f switch - 2

Now you can easily observe that using copyFromLocal with -f switch does not produce any error or it will easily update or modify your file in HDFS.


Article Tags :

Similar Reads