🖥

Linux — 既に存在するディレクトリを mkdir しようとしたときのエラーを無視する ( $ mkdir -p )

に公開
mkdir -p some_dir

と書けば、何度やっても怒られない。

実際にはエラーを無視するのではなく「既にディレクトリが存在する場合は何もしない」という動作らしい。

Help

$ man mkdir | cat

MKDIR(1)                  BSD General Commands Manual                 MKDIR(1)

NAME
     mkdir -- make directories

SYNOPSIS
     mkdir [-pv] [-m mode] directory_name ...

...

     -p      Create intermediate directories as required.  If this option is
             not specified, the full path prefix of each operand must already
             exist.  On the other hand, with this option specified, no error
             will be reported if a directory given as an operand already
             exists.  Intermediate directories are created with permission
             bits of rwxrwxrwx (0777) as modified by the current umask, plus
             write and search permission for the owner.

参考

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

https://line.me/ti/g2/eEPltQ6Tzh3pYAZV8JXKZqc7PJ6L0rpm573dcQ

Twitter

https://twitter.com/YumaInaura

公開日時

2016-06-27

Discussion