古いファイルを上書きせずにファイルをコピーする方法を知りたいのですが、利用できる -n スイッチがありません。
私が知る限り、cp -u と rsync の両方が古いファイルを上書きしますが、この動作は望ましくありません。常に古いファイルを保持したいと思います。
ありがとう
" --interactive
" オプション ( my cp
fromに存在GNU coreutils 6.12
) を使用して、上書きする前にプロンプトを表示し、デフォルトを入力できます。
echo 'n' | cp --interactive ~/somefile.txt ~/somefile_already_exists.txt
Copy the file to a newly created temporary file in the same directory (see mktemp
or tempfile
under Linux). Then use ln
to attempt to give the copy the name you want. ln
will fail if the name exists; you could try to use a different name, or just issue an error message, or whatever. Finally, remove the temporary name.