public static Result setFileOwner(String path, String ownerName) {
    if (LINUX) {
      // Set the file owner, if the owner's username is given
      if (!StringUtils.isEmpty(ownerName)) {
        try {
          return runCommand(new String[]{"chown", ownerName, path}, null, null, true);
        } catch (IOException | InterruptedException e) {
          // Improbable
          LOG.warn(String.format("Can not perform chown %s %s", ownerName, path), e);
          return new Result(-1, "", "Cannot perform operation: " + e.getLocalizedMessage());
        }
      } else {
        return new Result(0, "", "");
      }
    } else {
      LOG.debug(String.format("Not performing chown command for file %s " +
          "because current OS is not Linux ", path));
      return new Result(-1, "", "Cannot perform operation: The current OS is not Linux");
    }
  }
Sets the owner for a file.

@param path      the path to the file
@param ownerName the owner's local username
@return the result of the operation
ambari-server/src/main/java/org/apache/ambari/server/utils/ShellCommandUtil.java