📖 Scenario: You work in a company that stores large files on Hadoop Distributed File System (HDFS). You need to practice reading from and writing to HDFS using simple commands and scripts.
🎯 Goal: Learn how to write a file to HDFS, read it back, and display its contents using Hadoop commands.
📋 What You'll Learn
Create a local text file with specific content
Write the local file to HDFS
Read the file from HDFS
Display the file contents on the console
💡 Why This Matters
🌍 Real World
HDFS is used to store large data files across many computers. Reading and writing files to HDFS is a daily task for data engineers and scientists working with big data.
💼 Career
Knowing how to handle files in HDFS is essential for roles like Hadoop administrator, data engineer, and big data analyst.
Progress0 / 4 steps
1
Create a local text file
Create a local text file called example.txt with the exact content: Hello HDFS!
Hadoop
Hint
Use the echo command to write text into a file.
2
Write the file to HDFS
Use the Hadoop command hdfs dfs -put example.txt /user/yourusername/ to write the local file example.txt to your HDFS home directory.
Hadoop
Hint
Use hdfs dfs -put to copy a local file to HDFS.
3
Read the file from HDFS
Use the Hadoop command hdfs dfs -cat /user/yourusername/example.txt to read and display the contents of the file from HDFS.
Hadoop
Hint
Use hdfs dfs -cat to read a file from HDFS and print it to the console.
4
Display the file contents
Run the full script to display the output. The output should be exactly Hello HDFS!
Hadoop
Hint
The output should show the text you wrote to the file.
Practice
(1/5)
1. What does the write operation in HDFS primarily do?
easy
A. Creates or overwrites files in the distributed file system
B. Reads data from files line by line
C. Deletes files from the system
D. Lists all files in a directory
Solution
Step 1: Understand the purpose of write operation in HDFS
The write operation is used to create new files or overwrite existing files in HDFS.
Step 2: Differentiate write from read and other operations