• Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us
TecAdmin
Menu
  • Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us

Hadoop Commands to Manage Files on HDFS

Written by Rahul, Updated on August 1, 2019

This tutorial helps you to learn to manage our files on HDFS in Hadoop. You will learn how to create, upload, download and list contents in HDFS. Below commands will help you to how to create a directory structure in HDFS, Copy files from local file system to HDFS and download files from HDFS to local files. Also how to do manage files in HDFS.

Create Directory in HDFS

Takes the path URI’s like an argument and creates a directory or multiple directories.

hdfs dfs -mkdir 

Remember that you must create a home directory in HDFS with your system’s username. For example, you are logged in as hduser on your system, So first create /user/hduser else you will get this error, Now create directory structure inside it

hdfs dfs -mkdir /user/hduser
hdfs dfs -mkdir /user/hduser/input
hdfs dfs -mkdir /user/hduser/output 
hdfs dfs -mkdir /user/hduser/input/text /user/hadoop/input/xml

Copy Files to HDFS

After creating directory structure, Now put some files to HDFS from your local file system.

hdfs dfs -put LOCAL_FILE HDFS_PATH

For example you have test1.txt in current directory and /tmp/test2.xml on your local file system.

hdfs dfs -put text1.txt /user/hduser/input/text/
hdfs dfs -put /tmp/text2.xml /user/hduser/input/xml/

List Files from HDFS

Use the following example commands to list the content of the directory in HDFS.

hdfs dfs -ls /user/hduser
hdfs dfs -ls /user/hduser/input/
hdfs dfs -ls /user/hduser/input/text/

Use -R to list files recursively inside directories. For example:

hdfs dfs -ls -R /user/hadoop/input/

Download Files from HDFS

At this point, you have learned how to copy and list files to HDFS. Now use following example commands to how to download/Copy files from HDFS to the local file system.

hdfs dfs -get /user/hduser/input/text/test1.txt /tmp/
hdfs dfs -get /user/hadoop/dir1/xml/test2.xml /tmp/

here /tmp is on system’s local file system.

Copy Files between HDFS Directories

You can easily copy files between HDFS file system using distcp option.

hdfs distcp /user/hduser/input/xml/text2.xml /user/hduser/output
hdfs distcp /user/hduser/input/text/text1.xml /user/hduser/output

Share it!
Share on Facebook
Share on Twitter
Share on LinkedIn
Share on Reddit
Share on Tumblr
Share on Whatsapp
Rahul
Rahul
Connect on Facebook Connect on Twitter

I, Rahul Kumar am the founder and chief editor of TecAdmin.net. I am a Red Hat Certified Engineer (RHCE) and working as an IT professional since 2009..

1 Comment

  1. Avatar Vidya Vinodini Reply
    August 22, 2017 at 4:53 am

    Hi
    This tutorial is very useful for me..I followed this for my hadoop installation…but while running wordcount example – javac -classpath $(HADOOP_CLASSPATH) -d ‘/home/hduser/Desktop/WordCountTutorial/tutorial_classes’ ‘/home/hduser/Desktop/WordCountTutorial/WordCount.java’ i am facing with the error

    HADOOP_CLASSPATH: command not found
    javac: invalid flag: /home/hduser/Desktop/WordCountTutorial/tutorial_classes
    Usage: javac
    use -help for a list of possible options
    so how can i fix the problem??

    Thankyou

Leave a Reply Cancel reply

Popular Posts

  • How To Install Python 3.9 on Ubuntu 20.04 5
  • How To Install Python 3.9 on Ubuntu 18.04 0
  • How to Use AppImage on Linux (Beginner Guide) 2
  • How to Install Python 3.9 on CentOS/RHEL 7 & Fedora 32/31 0
  • How To Install VNC Server on Ubuntu 20.04 1
© 2013-2020 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy