title: Cannot change file ownership from bash script
body: <p>I am trying to run the command </p>
  
  <pre><code>chown -R "$USER" /mnt/namenode 
  </code></pre>
  
  <p>from a bash script to change the ownership of the namenode folder and its sub-folders. When I type the command manually </p>
  
  <pre><code>sudo chown -R ubuntu /mnt/namenode 
  </code></pre>
  
  <p>it works, but not when I do it from the script. From the script, only the ownership of the namenode is changing, not its subfolders. Does anyone know how I might fix this?</p>
  
  <p>OK, I got it. My script was formatting the namenode after the ownership had been set. Before the format, the subfolders has the correct ownership recursively. After the format, the sub-folders' ownership was changing to root. So I made the following change:</p>
  
  <pre><code>echo 'Y' | /home/$USER/hadoop-2.2.0/bin/hadoop namenode -format
  sudo chown -R $USER:$USER /mnt/namenode
  sudo chown -R $USER:$USER /mnt/datanode
  </code></pre>
  
  <p>In other words, I set the ownership after I did the formatting.</p>