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.
touch -c cache.flagCorrect. 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.
touch -r cache.flagIncorrect. -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 / 一時ディレクトリ
- Use disposable files and directories for destructive or timestamp-related checks.
- Command details can vary slightly between GNU and non-GNU implementations.
Foundation review
Place the operation
The no-create behavior is independent from whether access time, modification time, or a reference timestamp is selected.
Check the side effect
Test both an existing and a missing pathname so that creation behavior is visible.