美文网首页大数据
008 10 个最常用的 Hadoop 命令及使用案例

008 10 个最常用的 Hadoop 命令及使用案例

作者: 胡巴Lei特 | 来源:发表于2019-08-03 13:43 被阅读0次

    In this blog, we are going to explore most frequently used commands in Hadoop. These commands aid in performing various HDFS file operations. These include copying a file, moving a file, showing the contents of the file, creating directories, etc. So let us begin with an introduction and then we will see different commands in Hadoop with examples.

    10 Most Frequently Used Hadoop Commands

    Top Hadoop Commands

    Hadoop stores petabytes of data using HDFS. HDFS is a distributed file system which stores structured to unstructured data. It provides redundant storage for files having humongous size. There are various commands to perform different file operations. Let us take a look at some of the important Hadoop commands.

    List of Hadoop Commands

    1. version

    Command Name:** version**

    Command Usage: version

    Example:

    1. hadoop version

    Commands in Hadoop

    Description: Shows the version of hadoop installed.

    You must read about Hadoop Distributed Cache

    2. mkdir

    Command Name:** mkdir**

    Command Usage: mkdir <path>

    Example:

    1. hdfs dfs -mkdir /user/dataflair/dir1

    Commands in Hadoop

    Description: This command takes the <path> as an argument and creates the directory.

    3. Is

    Command Name:** ls**

    Command Usage: ls <path>

    Example:

    1. hdfs dfs -ls /user/dataflair

    Commands in Hadoop

    Description: This command displays the contents of the directory specified by <path>. It shows the name, permissions, owner, size and modification date of each entry.

    Do you know about Hadoop Automatic Failover?

    Second Example:

    1. hdfs dfs -ls -R /user

    <insert image ls-R.png>

    Description: This command behaves like ls but displays entries in all the sub-directories recursively

    4. put

    Command Name:** put**

    Command Usage: put <localsrc> <dest>

    Example:

    1. hdfs dfs -put /home/sample.txt /user/dataflair/dir1

    Commands in Hadoop

    Description: This command copies the file in the local filesystem to the file in DFS.

    5. copyFrom Local

    Command Name: copyFrom Local

    Command Usage: copyFrom Local <localsrc> <dest>

    Example:

    1. hdfs dfs -copyFromLocal /home/sample /user/dataflair/dir1

    Description: This command is similar to put command. But the source should refer to local file.

    6. get

    Command Name:get

    Command Usage: get <src> <localdest>

    Example:

    1. hdfs dfs -get /user/dataflair/dir1 /home

    Commands in Hadoop

    Description: This** Hadoop shell command** copies the file in HDFS identified by <src> to file in local file system identified by <localdest>

    Second Example:

    1. hdfs dfs -getmerge /user/dataflair/dir1/sample.txt /user/dataflair/dir2/sample2.txt /home/sample1.txt

    Commands in hadoop

    Description: This HDFS command retrieves all files in the source path entered by the user in HDFS. And merges them into one single file created in the local file system identified by local destination.

    Third Example:

    1. hadoop fs –getfacl /user/dataflair/dir1

    commands in Hadoop

    Fourth Example:

    1. hadoop fs –getfacl -R /user/dataflair/dir1

    commands in Hadoop

    Description: This Hadoop command shows the Access Control Lists (ACLs) of files and directories. This command displays default ACL if the directory contains the same.

    Options : -R: It recursively displays a list of all the ACLs of all files and directories.

    Fifth Example:

    1. hadoop fs –getfattr –d /user/dataflair/dir1

    Commands in Hadoop

    Description: This HDFS command displays if there is any extended attribute names and values for the specified file or directory.

    Options:-R: It lists the attributes for all files and directories recursively. -n name: It shows the named extended attribute value. -d: It shows all the extended attribute values associated with the pathname. -e encoding: Encodes values after extracting them. The valid coded forms that are “text”, “hex”, and “base64”. The values which are encoded as text strings gets enclosed with double quotes (” “). It uses prefix 0x for hexadecimal conversion. And 0s for all the values which gets coded as base64.

    Don’t forget to learn about Hadoop Schedulers

    7. copyToLocal

    Command Name: copyToLocal

    Command Usage: copyToLocal <src> <localdest>

    Example:

    1. hdfs dfs -copyToLocal /user/dataflair/dir1 /home

    commands in hadoop

    Description: It is similar to get command. Only the difference is that in this the destination of copied file should refer to a local file.

    8. cat

    Command Name:** cat**

    Command Usage: cat <file-name>

    Example:

    1. hdfs dfs -cat /user/dataflair/dir1/sample.txt

    commands in hadoop

    Description: This Hadoop shell command displays the contents of file on console or stdout.

    9. mv

    Command Name:** mv**

    Command Usage: mv <src> <dest>

    Example:

    1. hdfs dfs -mv /user/dataflair/dir1/sample.txt /user/dataflair/dir2

    commands in hadoop

    Description: This Hadoop shell command moves the file from the specified source to destination within HDFS.

    Have a look at HDFS Disk Balancer

    10. cp

    Command Name:** cp**

    Command Usage: cp <src> <dest>

    Example:

    1. hdfs dfs -cp /user/dataflair/dir2/sample.txt /user/dataflair/dir1

    Commands in hadoop

    Description: This Hadoop shell command copies the file or directory from given source to destination within HDFS.

    You must check 50 most asked Hadoop interview questions

    Summary

    There are many commands in “$HADOOP_HOME/bin/hadoop fs” other than what we have discussed in this tutorial. What we have covered are the frequently used basic commands to get started. If you are stuck somewhere then type the following:

    1. $HADOOP_HOME/bin/hadoop fs -help commandName

    This will display a short usage summary of the command specified.

    Still, if you have any questions related to Hadoop Commands, ask in the comment section. We will definitely get back to you.

    https://data-flair.training/blogs/commands-in-hadoop/

    相关文章

      网友评论

        本文标题:008 10 个最常用的 Hadoop 命令及使用案例

        本文链接:https://www.haomeiwen.com/subject/rmjjdctx.html