{"record":{"id":"c1d0b10e8fd8762e","repo":"apache/hadoop","slug":"no-such-file-or-directory-c1d0b1","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/Mkdir.java","lineNumber":84,"sourceCode":"    }\n  }\n\n  @Override\n  protected void processNonexistentPath(PathData item) throws IOException {\n    if (!createParents) {\n      // check if parent exists. this is complicated because getParent(a/b/c/) returns a/b/c, but\n      // we want a/b\n      final Path itemPath = new Path(item.path.toString());\n      final Path itemParentPath = itemPath.getParent();\n\n      if(itemParentPath == null) {\n        throw new PathNotFoundException(String.format(\n            \"Item: %s parent's path is null. This can happen if mkdir is \" +\n                \"called on root, so there's no parent.\", itemPath.toString()));\n      }\n\n      if (!item.fs.exists(itemParentPath)) {\n        throw new PathNotFoundException(itemParentPath.toString());\n      }\n    }\n    if (!item.fs.mkdirs(item.path)) {\n      throw new PathIOException(item.toString());\n    }\n  }\n}\n","sourceCodeStart":66,"sourceCodeEnd":92,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Mkdir.java#L66-L92","documentation":"Thrown by the shell 'mkdir' command (Mkdir.processNonexistentPath, Mkdir.java:84) when the directory to create does not exist AND its parent directory also does not exist. This check only runs when the -p flag was NOT given; PathNotFoundException's default message is 'No such file or directory'. It exists because plain mkdir, unlike mkdirs(), refuses to silently create intermediate directories.","triggerScenarios":"Running 'hadoop fs -mkdir /user/alice/newdir' when /user/alice does not exist. Any shell mkdir invocation (without -p) whose target's parent is missing, including parents missing due to a typo in an intermediate path segment. Only reached via processNonexistentPath, i.e. the target itself does not already exist.","commonSituations":"Scripts ported from Linux 'mkdir -p' habits that assume parents are auto-created; bootstrapping a new user/tool directory tree on a fresh HDFS namespace; typo'd intermediate path components; CI jobs that assume a previous step created the base directory.","solutions":["Re-run with the -p flag: 'hadoop fs -mkdir -p /user/alice/newdir' (createParents=true skips the parent check)","Create the missing parent level(s) explicitly first: 'hadoop fs -mkdir /user/alice' then 'hadoop fs -mkdir /user/alice/newdir'","Check for typos in the intermediate path components with 'hadoop fs -ls' on the expected parent","In code, call FileSystem.mkdirs(path) instead of issuing a shell mkdir without -p"],"exampleFix":"# before\nhadoop fs -mkdir /data/logs/2026/08\n# mkdir: `/data/logs/2026/08': No such file or directory\n\n# after\nhadoop fs -mkdir -p /data/logs/2026/08","handlingStrategy":"validation","validationCode":"// before creating, ensure the parent chain exists\nPath dst = new Path(\"/user/alice/newdir\");\nif (!fs.exists(dst.getParent())) {\n  fs.mkdirs(dst.getParent()); // creates all intermediates\n}\nfs.mkdirs(dst);","typeGuard":null,"tryCatchPattern":"catch (PathNotFoundException e) { /* create parents, then retry once */ fs.mkdirs(parent); fs.mkdirs(dst); }","preventionTips":["Default to 'hadoop fs -mkdir -p' in scripts","Verify parent with 'hadoop fs -test -d' before plain mkdir","In code prefer FileSystem.mkdirs() over shell mkdir without -p"],"tags":["hdfs","mkdir","path-not-found","hadoop-shell","parent-directory"],"backgroundTag":"parent-directory-missing","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}