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 CommandsTop 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:
- hadoop version
Description: Shows the version of hadoop installed.
You must read about Hadoop Distributed Cache
2. mkdir
Command Name:** mkdir**
Command Usage: mkdir <path>
Example:
- hdfs dfs -mkdir /user/dataflair/dir1
Description: This command takes the <path> as an argument and creates the directory.
3. Is
Command Name:** ls**
Command Usage: ls <path>
Example:
- hdfs dfs -ls /user/dataflair
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:
- 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:
- hdfs dfs -put /home/sample.txt /user/dataflair/dir1
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:
- 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:
- hdfs dfs -get /user/dataflair/dir1 /home
Description: This** Hadoop shell command** copies the file in HDFS identified by <src> to file in local file system identified by <localdest>
Second Example:
- hdfs dfs -getmerge /user/dataflair/dir1/sample.txt /user/dataflair/dir2/sample2.txt /home/sample1.txt
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:
- hadoop fs –getfacl /user/dataflair/dir1
Fourth Example:
- hadoop fs –getfacl -R /user/dataflair/dir1
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:
- hadoop fs –getfattr –d /user/dataflair/dir1
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:
- hdfs dfs -copyToLocal /user/dataflair/dir1 /home
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:
- hdfs dfs -cat /user/dataflair/dir1/sample.txt
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:
- hdfs dfs -mv /user/dataflair/dir1/sample.txt /user/dataflair/dir2
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:
- hdfs dfs -cp /user/dataflair/dir2/sample.txt /user/dataflair/dir1
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:
- $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.
网友评论