LoginSignup
0
2

More than 5 years have passed since last update.

先頭に - (ハイフン) が付いたファイルを削除する方法

Posted at

vim などでちょっとした拍子に先頭に - が付いたファイルを作成してしまった場合の削除方法について。

$ ls
-rw-r--r--   1 hoge  hoge   5432  8 26 14:54 -h

$ rm -f '-h'
rm: illegal option -- h
usage: rm [-f | -i] [-dPRrvW] file ...
       unlink file

$ rm -f "¥-h"
rm: illegal option -- h
usage: rm [-f | -i] [-dPRrvW] file ...
       unlink file

$ # ちくしょう...

A. -- を使う

$ rm -f -- -h

$ ls

やったね!

-- って何?

"--" は特殊な引き数で、スキャンのモードによらず、 オプションのスキャンを強制的に終了させる。

  • コマンドライン引数に指定されたオプションの指定の最後を意味するものらしい
  • getopt とかこれが機能するものもあれば、考慮されていないやつもある
  • 呼び名不明
0
2
2

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
2