You are on page 1of 2

To implement the following file management tasks in Hadoop System (HDFS): Adding

files and directories, Retrieving files, Deleting files

To implement file management tasks in the Hadoop Distributed File System (HDFS),
you can use the Hadoop command-line interface (`hadoop fs` commands). Here's a
brief guide on how to perform the specified tasks:

### 1. Adding Files and Directories:

#### Add a File:


```bash
hadoop fs -copyFromLocal local-file-path hdfs-target-directory
```
Replace `local-file-path` with the path to the file on your local machine and
`hdfs-target-directory` with the target directory in HDFS.

#### Add a Directory:


```bash
hadoop fs -copyFromLocal local-directory-path hdfs-target-directory
```
Replace `local-directory-path` with the path to the local directory and `hdfs-
target-directory` with the target directory in HDFS.

### 2. Retrieving Files:

#### Retrieve a File:


```bash
hadoop fs -copyToLocal hdfs-source-file local-target-directory
```
Replace `hdfs-source-file` with the path to the file in HDFS and `local-target-
directory` with the target directory on your local machine.

### 3. Deleting Files:

#### Delete a File:


```bash
hadoop fs -rm hdfs-file-path
```
Replace `hdfs-file-path` with the path to the file in HDFS.

#### Delete a Directory (and its contents):


```bash
hadoop fs -rm -r hdfs-directory-path
```
Replace `hdfs-directory-path` with the path to the directory in HDFS.

### Examples:

#### Adding a File:


```bash
hadoop fs -copyFromLocal /local/path/myfile.txt /user/hadoop/hdfs-directory/
```

#### Retrieving a File:


```bash
hadoop fs -copyToLocal /user/hadoop/hdfs-directory/myfile.txt /local/path/
```

#### Deleting a File:


```bash
hadoop fs -rm /user/hadoop/hdfs-directory/myfile.txt
```

#### Deleting a Directory:


```bash
hadoop fs -rm -r /user/hadoop/hdfs-directory/
```

Remember to replace the placeholder paths with your actual file and directory
paths. Additionally, ensure that you have the necessary permissions to perform
these operations in HDFS.

You might also like