LoginSignup
56
30

More than 5 years have passed since last update.

CentOSのcpコマンドで強制的にファイルを上書きする

Posted at

cpコマンドでファイルを強制的に上書きしたいが、-fオプションを付けても上書きしてよいか確認されてしまう。

# cp -f sample.txt sample2.txt 
cp: overwrite `sample2.txt'? 

原因

原因はエリアスで予めcpコマンドがcp -iと設定されているため。

# alias
alias cp='cp -i'

-iオプションは-fの反対で常に上書きする前に確認をする。

  -i, --interactive            prompt before overwrite (overrides a previous -n
                                  option)

回避方法

cpコマンドの前にバックスラッシュを付けることでエイリアスを無効にして実行する。

\cp -f sample.txt sample2.txt 

これで確認無しでファイルを上書きすることができる。

56
30
1

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
56
30