Hadoop FS Copy
Hadoop FS Copy is a command used to copy files and directories between Hadoop Distributed File System (HDFS) locations. Hadoop provides a command-line interface called hadoop fs
that allows you to interact with HDFS and perform various file and directory operations, including copying data. The copyFromLocal
and copyToLocal
commands are commonly used for copying data to and from HDFS.
Here’s how you can use hadoop fs
to copy data in HDFS:
Copy from Local to HDFS (copyFromLocal):
- The
copyFromLocal
command is used to copy files or directories from your local file system into HDFS. - The basic syntax is:
shellhadoop fs -copyFromLocal <local-source> <hdfs-destination>
For example, to copy a local file named
localfile.txt
to an HDFS directory named/user/hadoop/hdfsdir
, you would use:shellhadoop fs -copyFromLocal localfile.txt /user/hadoop/hdfsdir
- The
Copy from HDFS to Local (copyToLocal):
- The
copyToLocal
command is used to copy files or directories from HDFS to your local file system. - The basic syntax is:
shellhadoop fs -copyToLocal <hdfs-source> <local-destination>
For example, to copy a file named
hdfspath/file.txt
from HDFS to your local directory/localpath
, you would use:shellhadoop fs -copyToLocal hdfspath/file.txt /localpath
- The
Recursive Copy:
- You can use the
-r
or--recursive
option to perform a recursive copy of directories and their contents.
shellhadoop fs -copyFromLocal -r localdir /user/hadoop/hdfsdir
This command copies the entire contents of the local directory
localdir
to the HDFS directory/user/hadoop/hdfsdir
.- You can use the
Overwriting Existing Files:
- By default, if a file with the same name already exists in the destination location, Hadoop will not overwrite it.
- To force overwriting, you can use the
-f
option.
shellhadoop fs -copyFromLocal -f localfile.txt /user/hadoop/hdfsdir
Hadoop Training Demo Day 1 Video:
Conclusion:
Unogeeks is the No.1 IT Training Institute for Hadoop Training. Anyone Disagree? Please drop in a comment
You can check out our other latest blogs on Hadoop Training here – Hadoop Blogs
Please check out our Best In Class Hadoop Training Details here – Hadoop Training
Follow & Connect with us:
———————————-
For Training inquiries:
Call/Whatsapp: +91 73960 33555
Mail us at: info@unogeeks.com
Our Website ➜ https://unogeeks.com
Follow us:
Instagram: https://www.instagram.com/unogeeks
Facebook:https://www.facebook.com/UnogeeksSoftwareTrainingInstitute
Twitter: https://twitter.com/unogeeks