Hadoop FS Shell mv

LabEx
2 min readJun 18, 2024

--

Cover

Introduction

Imagine you are in the ancient empire of Naruda, where Emperor Jason has ordered the relocation of ancient scrolls containing valuable knowledge from one library to another. Your task is to simulate this scenario in the context of Hadoop Distributed File System (HDFS) using the Hadoop FS Shell mv command. Your goal is to successfully move the scrolls from one directory to another without losing any data.

Move Ancient Scroll

In this step, you will move an ancient scroll named ancient_scroll.txt from the /documents directory to the /archives directory using the Hadoop FS Shell mv command.

  1. First, use the su - hadoop command to switch to the hadoop user, and then explore the ancient_scroll.txt file in the /documents directory.
  • hdfs dfs -ls / hdfs dfs -ls /documents hdfs dfs -cat /documents/ancient_scroll.txt
  1. Next, move the ancient_scroll.txt file to the /archives directory.
  • hdfs dfs -mv /documents/ancient_scroll.txt /archives

Here’s an explanation of the command and its components:

  • hdfs dfs: This is the prefix of the command that invokes the Hadoop file system client, and is used to perform operations that interact with HDFS.
  • mv: This parameter specifies that the operation to be performed is move, which is similar to the mv command in Unix/Linux, and can be used to rename a file or move a file from one location to another.
  • /documents/ancient_scroll.txt: This part specifies the HDFS path and name of the source file. It tells Hadoop which file you want to move. In this example, the source file is ancient_scroll.txt located in the /documents directory of HDFS.
  • /archives/: This part specifies the HDFS path to the destination directory. It tells Hadoop which directory you want to move the source files to. In this example, the target directory is the /archives directory of HDFS.

Update Scroll Location

In this step, you will update the location of the ancient scroll in the metadata without physically moving the file.

  1. Check the current location of the ancient_scroll.txt file.
  • hdfs dfs -ls /archives/ancient_scroll.txt
  1. Update the location information of the file to reflect a new path.
  • hdfs dfs -mv /archives/ancient_scroll.txt /library/archives/ancient_scroll.txt

Summary

In this lab, the focus was on practicing the Hadoop FS Shell mv command within the HDFS environment. By simulating the movement of ancient scrolls in a fictional empire setting, users can grasp the concept of transferring files in Hadoop effectively. The step-by-step guidance ensures that learners can understand the process clearly and apply the knowledge gained in similar scenarios.

Want to learn more?

Join our Discord or tweet us @WeAreLabEx ! 😄

--

--

LabEx

LabEx is an AI-assisted, hands-on learning platform for tech enthusiasts, covering Programming, Data Science, Linux and other areas.