{"record":{"id":"21158eadd140844a","repo":"apache/hadoop","slug":"no-such-file-or-directory-21158e","errorCode":null,"errorMessage":"No such file or directory","messagePattern":"No such file or directory","errorType":"exception","errorClass":"PathNotFoundException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CommandWithDestination.java","lineNumber":213,"sourceCode":"  }\n\n  /**\n   *  The last arg is expected to be a remote path, if only one argument is\n   *  given then the destination will be the remote user's directory \n   *  @param args is the list of arguments\n   *  @throws PathIOException if path doesn't exist or matches too many times \n   */\n  protected void getRemoteDestination(LinkedList<String> args)\n  throws IOException {\n    if (args.size() < 2) {\n      dst = new PathData(Path.CUR_DIR, getConf());\n    } else {\n      String pathString = args.removeLast();\n      // if the path is a glob, then it must match one and only one path\n      PathData[] items = PathData.expandAsGlob(pathString, getConf());\n      switch (items.length) {\n        case 0:\n          throw new PathNotFoundException(pathString);\n        case 1:\n          dst = items[0];\n          break;\n        default:\n          throw new PathIOException(pathString, \"Too many matches\");\n      }\n    }\n  }\n\n  @Override\n  protected void processArguments(LinkedList<PathData> args)\n  throws IOException {\n    // if more than one arg, the destination must be a directory\n    // if one arg, the dst must not exist or must be a directory\n    if (args.size() > 1) {\n      if (!dst.exists) {\n        throw new PathNotFoundException(dst.toString());\n      }","sourceCodeStart":195,"sourceCodeEnd":231,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CommandWithDestination.java#L195-L231","documentation":"Thrown by CommandWithDestination.getRemoteDestination() when the DESTINATION argument of -put/-cp/-moveFromLocal/-appendToFile is a glob pattern and PathData.expandAsGlob() returns zero matches. PathNotFoundException (a PathIOException subclass) renders as 'dest: No such file or directory'. Important nuance: a plain non-glob destination that does not exist is fine (globStatus returns null and a placeholder PathData with null stat is created) - the exception requires glob metacharacters that match nothing.","triggerScenarios":"'hdfs dfs -put local.txt /user/me/backup-*' when nothing matches backup-*; a mistyped destination glob like '/dat/*' instead of '/data/*'; brace or character-class patterns matching zero entries.","commonSituations":"Scripts templating the destination with wildcards that assume at least one file already exists; renamed directories making a previously-matching glob stale; users expecting put-to-new-file semantics while accidentally including '*' or '?' in the destination.","solutions":["Remove glob metacharacters from the destination and give the exact target path or directory ('/user/me/newname' or an existing dir)","Verify the parent directory exists and the glob is spelled correctly ('hdfs dfs -ls /user/me/backup-*')","If the destination must be pattern-generated, pre-resolve it in the shell before calling put"],"exampleFix":"# before\nhdfs dfs -put metrics.tsv /warehouse/daily-*\n# after\nhdfs dfs -put metrics.tsv /warehouse/daily/2026-08-22.tsv","handlingStrategy":"validation","validationCode":"// if the destination is a glob, verify it matches exactly one path before copying\nFileSystem fs = dstPath.getFileSystem(conf);\nFileStatus[] m = fs.globStatus(dstPath);\nif (m == null) { /* not a glob: fine, new path allowed */ }\nelse if (m.length == 0) throw new FileNotFoundException(\"destination glob matches nothing: \" + dstPattern);","typeGuard":null,"tryCatchPattern":"try {\n  shellRun(\"-put\", localSrc, dstPattern);\n} catch (PathNotFoundException e) {\n  // e.getPath() is the destination glob that matched nothing; fall back to an explicit path\n  shellRun(\"-put\", localSrc, defaultDstPath());\n}","preventionTips":["Avoid glob metacharacters in destinations; reserve wildcards for source arguments","Pre-resolve templated destinations in the driving script so the shell receives a literal path","Run 'hdfs dfs -ls <pattern>' as a cheap pre-flight check when a glob destination is unavoidable"],"tags":["hadoop","hdfs","glob","path-not-found","copy","shell"],"backgroundTag":"path-not-found","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}