Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hadoop commands

Tags:

hadoop

hdfs

I have Hadoop installed in this location

/usr/local/hadoop$

Now I want to list the files inside the dfs. The command I used is :

hduser@ubuntu:/usr/local/hadoop$ bin/hadoop dfs -ls

This gave me the files in the dfs

Found 3 items
drwxr-xr-x   - hduser supergroup          0 2014-03-20 03:53 /user/hduser/gutenberg
drwxr-xr-x   - hduser supergroup          0 2014-03-24 22:34 /user/hduser/mytext-output
-rw-r--r--   1 hduser supergroup        126 2014-03-24 22:30 /user/hduser/text.txt

Next time, I tried the same command in a different manner

hduser@ubuntu:/usr/local/hadoop$ hadoop dfs -ls

It also gave me the same result.

Could some one please explain why both are working despite of executing the ls command from different folders. I hope you guys understood my question.Just explain me difference between these two :

hduser@ubuntu:/usr/local/hadoop$ bin/hadoop dfs -ls
hduser@ubuntu:/usr/local/hadoop$ hadoop dfs -ls
like image 405
Francis S Avatar asked Mar 26 '14 07:03

Francis S


People also ask

Where do Hadoop commands run?

These hadoop hdfs commands can be run on a pseudo distributed cluster or from any of the VM's like Hortonworks, Cloudera, etc.

How many hdfs commands are there?

Hadoop provides two types of commands to interact with File System; hadoop fs or hdfs dfs .

How do I list files in hdfs?

Use the hdfs dfs -ls command to list files in Hadoop archives. Run the hdfs dfs -ls command by specifying the archive directory location. Note that the modified parent argument causes the files to be archived relative to /user/ .

Which command is used to start hdfs?

Run the command % $HADOOP_INSTALL/hadoop/bin/start-dfs.sh on the node you want the Namenode to run on. This will bring up HDFS with the Namenode running on the machine you ran the command on and Datanodes on the machines listed in the slaves file mentioned above.


2 Answers

In unix an executable file can be executed in two ways, either by giving the absolute/relative path or commands in system executables path(path should be specified in PATH variable)

When you execute bin/hadoop dfs -ls should be inside the directory /usr/local/hadoop. Or /usr/local/hadoop/bin/hadoop dfs -ls will also work

There is one environment variable PATH in unix which keeps in the list of executable location by default it keeps the following path /usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin: . Whenever we execute any command like ls, mkdir etc it is taking from the one location in PATH variable. When you give the command hadoop(it will be taken from the path /usr/local/hadoop/bin/). Since you have specified the path /usr/local/hadoop/bin/ in PATH variable. Use the following command to check the value of your PATH variable

echo $PATH
like image 111
SachinJ Avatar answered Sep 26 '22 04:09

SachinJ


You set a hadoop global path HADOOP_HOME in your ~/.bashrc file so that Hadoop commands will works in anywhere in Terminal.

like image 34
venkat4143 Avatar answered Sep 24 '22 04:09

venkat4143