LoginSignup
2
5

More than 3 years have passed since last update.

【macOS】rmコマンドでディレクトリを削除する

Posted at

はじめに

macOSなどUNIX系OSではrmコマンドでファイルを削除できます。しかししrmコマンドにディレクトリを指定すると次のようなエラーが表示され、削除出来ません。

rm dirname: is a directory

ここでは、その解決方法を記載します。

-rf オプションを使用する

-r オプションはrmコマンドの削除対象に、ディレクトリを含めるように指定します。
-f オプションはエラーを表示させないオプションです。
この2つのオプションを組み合わせる事で、確認なしディレクトリを削除できます。

rm dirname -rf

rmdirコマンドを使用する

rmコマンドの替わりにrmdirコマンドを使用します。

rmdir dirname

ただし、このコマンドを使用する際に削除したいディレクトリが空でない場合には次のようなエラーが表示されます。

rmdir: dirname: Directory not empty
2
5
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
2
5