LoginSignup
12
4

More than 3 years have passed since last update.

rmでフォルダ全削除する時、yes/noを全部yesで答えて一発で消す

Posted at

gitレポジトリをrmで削除する際、やたらyes/noを聞かれる

コマンドライン からフォルダを削除する際、大量のファイルにyes/noを聞かれることがある。

rm -r {folder_name}
override r--r--r--  user01/CATK\Domain Users for folder/.git/path/to/hashxxxxxxxxxxx? 
override r--r--r--  user01/CATK\Domain Users for folder/.git/path/to/hashyyyyyyyyyyy? 
override r--r--r--  user01/CATK\Domain Users for folder/.git/path/to/hashzzzzzzzzzzz? 

とにかく消したいので、全部yesで答えて欲しい。

使用するコマンドの答え

yes | rm -r {folder_name}

yesコマンドをパイプで渡すのがポイント。

コマンド解説

yesコマンドとは

実際にコマンドライン で打ってみれば分かるが、無限にyを出力するコマンドである。

$yes
y
y
y
y
y
y
y

任意の文字列を出すことも出来る

yesの後に任意の文字列を渡せば、y同様任意の文字列を無限に出すことが出来る。

$yes hoge
hoge
hoge
hoge
hoge
hoge
hoge
hoge

yesを使って自動的にyes / noを答える

yesをパイプで後続のコマンドに渡すことで、後続のコマンドの出力結果(今回で言えばyes / noを聞かれるファイル数)がいくつであれ、全てyesで答えることができる。

yes | {command}

従って

yes | rm -r {folder_name}

とすることで、rmコマンドを実行した結果聞かれるyes / noに全てyesで答えられる。

12
4
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
12
4