draft.conf exists in the current directory.
Change its name to app.conf without changing the contents or directory.
Which command is correct?
mv performs both moves and renames. Two paths in the same directory produce a rename, and the old name is removed.
Detailed explanation
cp draft.conf app.confIncorrect. cp creates another file and leaves draft.conf in place.
Incorrect. cp creates another file and leaves draft.conf in place.
rm draft.conf app.confIncorrect. rm deletes files instead of renaming them.
Incorrect. rm deletes files instead of renaming them.
touch app.confIncorrect. touch creates or timestamps a file but does not rename draft.conf.
Incorrect. touch creates or timestamps a file but does not rename draft.conf.
mv draft.conf app.confCorrect. mv changes the filename in place without changing its contents.
Correct. mv changes the filename in place without changing its contents.
Try it yourself
An example you can run in a temporary verification environment.
LAB_DIR=$(mktemp -d)
printf demo > "$LAB_DIR/draft.conf"
mv "$LAB_DIR/draft.conf" "$LAB_DIR/app.conf"
cat "$LAB_DIR/app.conf"
rm -r "$LAB_DIR"Expected result
demoKey points
- mv moves and renames
- Unlike cp, the old name is not retained
- Take care with an existing destination
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.