title: sudo hadoop vs su hadoop
body: <p>Has anybody got into a strange environment issue and been forced to use SU rather than SUDO when calling hadoop commands?</p>
  
  <pre><code>sudo su -c 'hadoop fs -ls /' hdfs
  </code></pre>
  
  <pre>
  Found 4 items
  drwxr-xr-x   - hdfs   hdfs          0 2014-02-11 12:33 /apps
  drwx------   - mapred hdfs          0 2014-03-10 10:25 /mapred
  drwxrwxrwx   - hdfs   hdfs          0 2014-03-10 10:26 /tmp
  drwxr-xr-x   - hdfs   hdfs          0 2014-02-11 12:34 /user
  </pre>
  
  <p>The environment allows finding of the executable:</p>
  
  <pre><code>sudo -u hdfs 'hadoop' 
  </code></pre>
  
  <pre>
  Usage: hadoop [--config confdir] COMMAND
  where COMMAND is one of:
    namenode -format     format the DFS filesystem
  ...
    fs                   run a generic filesystem user client
  ...
  ...
  Most commands print help when invoked w/o parameters.
  </pre>
  
  <pre><code>sudo -u hdfs 'hadoop fs -ls /' 
  </code></pre>
  
  <pre>
  sudo: hadoop fs -ls: command not found
  </pre>
  
  <p>I wondered if it was an environment issue, but this gave me no hints:</p>
  
  <pre><code>sudo su -c 'env' hdfs | sort &gt;sudo_su.txt
  sudo -u hdfs 'env' | sort &gt;sudo.txt
  diff sudo.txt sudo_su.txt
  </code></pre>
  
  <pre>
  11a12
  > PWD=/home/user
  14c15,16
   SHLVL=1
  > SUDO_COMMAND=/bin/su -c env hdfs
  20a23
  > _=/usr/bin/env
  </pre>