Hadoop FS Shell mv
Tags: hadoop, coding, programming, tutorial
Published: 2024-06-20 20:12:10


## 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.

   ```hadoop
   hdfs dfs -ls /
   hdfs dfs -ls /documents
   hdfs dfs -cat /documents/ancient_scroll.txt
   ```

2. Next, move the `ancient_scroll.txt` file to the `/archives` directory.

   ```hadoop
   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.

   ```hadoop
   hdfs dfs -ls /archives/ancient_scroll.txt
   ```

2. Update the location information of the file to reflect a new path.

   ```hadoop
   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?

- 🚀 Practice [Hadoop FS Shell mv](https://labex.io/tutorials/hadoop-hadoop-fs-shell-mv-271874)
- 🌳 Learn the latest [Hadoop Skill Trees](https://labex.io/skilltrees/hadoop)
- 📖 Read More [Hadoop Tutorials](https://labex.io/tutorials/category/hadoop)

Join our [Discord](https://discord.gg/J6k3u69nU6) or tweet us [@WeAreLabEx](https://twitter.com/WeAreLabEx) ! 😄