public static void main(String[] args) throws Exception {

    Params params = new Params();
    new JCommander(params, args);

    TestDanglingQOuts c = new TestDanglingQOuts();

    Set<File> unused = Sets.difference(c.outsFound, c.outsNeeded.keySet());

    for (File file : unused) {
      System.out.println(file);
      if (params.delete) {
        file.delete();
      }
    }
  }
This test ensures that there are no dangling q.out files in the project

It has a cli functionlity to remove them if there are any.
itests/util/src/test/java/org/apache/hadoop/hive/cli/control/TestDanglingQOuts.java