Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

9
  • 5
    No - not unless /dir1/ definitely already exists. Use mkdir -p /dir1/dir2 and forget the test. Commented Feb 20, 2015 at 6:47
  • ya, Dir1 already existed, it was the end of the path of my home directory. We had to run it as a test, I didn't get the extra credit for it and was wondering if it was incorrect. Thank you. Commented Feb 20, 2015 at 6:55
  • mkdir -p will fail as well if dir2 exists as a file other than a directory - or if permissions forbid you to create dirs for whatever reason. I usually do like mkdir -p ./target/dir && cd ./target/dir || exit Commented Feb 20, 2015 at 7:06
  • Assuming there exists no issues with permissions,and that dir2 doesn't already exist as a file, my test will work, correct? I can't run to check atm. Commented Feb 20, 2015 at 7:10
  • I'm not using mkdir -p. Dir1 already exists, i'm testing to see if dir2 exists as a subdirectory of dir1, and to create it only if it doesn't exist. Why would I need to test for dir1 as well? Commented Feb 20, 2015 at 7:18