LoginSignup
0
0

More than 1 year has passed since last update.

mkdir を使う時は -p オプションがオススメ!

Posted at

なぜ mkdir -p をお勧めするか。

親ディレクトリにが存在しない場合に、親ディレクトリを作成してくれるからです。

解説

今まで mkdir を使う時は、オプションなしで実行していました。

ただ、下のケースで、hello ディレクトリがない場合は、エラーが出てしまいます。

$ mkdir hello/workspace
mkdir: hello: No such file or directory

-p をつけると、親ディレクトリも作成してくれます。

$ mkdir -p
$ ls
hello/workspace

結論

mkdir を親ディレクトリ込みで実行する時は、その場所に親ディレクトリがあることを想定しているので、どんな時でも、$ mkdir -p で実行して良いと思います。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0