Copy src/report.csv to dest/report.csv.
If the destination exists and is newer than the source, do not overwrite it.
Which GNU cp command is appropriate?
cp -u copies only when the destination is missing or older than the source.
Detailed explanation
cp -f src/report.csv dest/report.csvIncorrect. -f forces overwriting and is the opposite of the requirement.
Incorrect. -f forces overwriting and is the opposite of the requirement.
cp -i src/report.csv dest/report.csvIncorrect. -i prompts but does not compare timestamps automatically.
Incorrect. -i prompts but does not compare timestamps automatically.
cp -n src/report.csv dest/report.csvIncorrect. -n skips an existing destination regardless of age.
Incorrect. -n skips an existing destination regardless of age.
cp -u src/report.csv dest/report.csvCorrect. cp -u copies only a missing or older destination.
Correct. cp -u copies only a missing or older destination.
Try it yourself
An example you can run in a temporary verification environment.
tmp=$(mktemp -d); printf old >"$tmp/src"; sleep 1; printf newer >"$tmp/dst"; cp -u "$tmp/src" "$tmp/dst"; cat "$tmp/dst"; rm -rf "$tmp"Expected result
newerKey points
- -u updates only
- -n skips existing destinations
- -i asks for confirmation
Notes
- Environment: GNU coreutils 9.x / 一時ファイル
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.