2

古いファイルを上書きせずにファイルをコピーする方法を知りたいのですが、利用できる -n スイッチがありません。

私が知る限り、cp -u と rsync の両方が古いファイルを上書きしますが、この動作は望ましくありません。常に古いファイルを保持したいと思います。

ありがとう

4

3 に答える 3

3

" --interactive" オプション ( my cpfromに存在GNU coreutils 6.12) を使用して、上書きする前にプロンプ​​トを表示し、デフォルトを入力できます。

echo 'n' | cp --interactive ~/somefile.txt ~/somefile_already_exists.txt
于 2013-07-12T16:35:58.917 に答える
1

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.

于 2013-07-12T17:01:50.523 に答える