Hadoop Learning notes 0002--hdfs file operations

Source: Internet
Author: User
Tags hadoop fs

Hadoop Study Notes 0002 -- HDFS file Operations

Description: Hadoop of HDFS file operations are often done in two ways, command-line mode and Javaapi Way.

Mode one: Command line mode

Hadoop the file Operation command form is: Hadoop fs-cmd <args>

Description: cmd is the specific file Operation command, <args> is a set of variable numbers of parameters.

Hadoop The most commonly used file manipulation commands include adding files and directories, getting files, deleting files, and so on.

1 Add files and directories

HDFS have a default working directory /usr/$USER , where $USER is your login username, the author's user name is Root . The directory cannot be created automatically and requires the mkdir command to be created.

Hadoop fs-mkdir/usr/root

Use Hadoop the command put the local file README.txt sent to HDFS .

Hadoop fs-put README.txt.

Note that the last parameter of the command above is a period ( . ), which means putting the local file into the default working directory, which is equivalent to:

Hadoop FS- put Readme.txt/user/root

Use Hadoop of the ls command, i.e.

Hadoop Fs-ls

Show Results 1 is shown.

Figure 1 Hadoop in ls Command Demo

2 Get File

getting the file contains two levels of meaning, one is HDFS get the file from the local file, the add file described earlier, and the local file from HDFS To get the file, you can use the Hadoop of the Get command. For example, if the local file does not have a README.txt file and needs to be retrieved from HDFS , you can execute the following command.

Hadoop fs-get README.txt.

Or

Hadoop Fs-get Readme.txt/usr/root/readme.txt

3 Deleting Files

Hadoop the Delete file command is RM . For example, to delete a README.txt uploaded from a local file , you can execute the following command.

Hadoop fs-rm README.txt

4 Retrieving Files

retrieving a file is a lookup HDFS the contents of the file in, you can use Hadoop in the Cat command. For example, to view The contents of a README.txt, you can execute the following command.

Hadoop Fs-cat README.txt

5 Check Help

Check Hadoop command Help that allows us to master and use it well Hadoop of the command. We can perform a full command column for Hadoop FS to get the version of Hadoop , or you can use the Help To show the usage and brief description of a specific command.

For example, to understand ls command, execute the following command.

Hadoop fs-help ls

about the Hadoop Command ls the description 3 is shown.

Figure 3 Hadoop Command ls the introduction

Hadoop Learning notes 0002--hdfs file operations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.