Update cache.flag's timestamp if it exists.
Do not create a new file when the name is absent.
Which command is appropriate?
touch -c or --no-create updates timestamps of existing files and does not create a missing name.
Detailed explanation
touch cache.flagIncorrect. Plain touch creates the file if it does not exist.
Incorrect. Plain touch creates the file if it does not exist.
touch -c cache.flagCorrect. touch -c cache.flag updates an existing file without creating it.
Correct. touch -c cache.flag updates an existing file without creating it.
touch -a cache.flagIncorrect. -a limits which timestamp is updated but does not suppress creation.
Incorrect. -a limits which timestamp is updated but does not suppress creation.
touch -r cache.flagIncorrect. -r copies timestamps from a reference file and still has different semantics.
Incorrect. -r copies timestamps from a reference file and still has different semantics.
Try it yourself
An example you can run in a temporary verification environment.
tmp=$(mktemp -d); touch -c "$tmp/missing"; test ! -e "$tmp/missing" && echo not-created; rmdir "$tmp"Expected result
not-createdKey points
- -c prevents creation
- touch alone creates if missing
- -a updates access time
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.