Rename draft.conf to service.conf in the same directory.
Which command is appropriate?
mv changes a directory entry's name when source and destination are in the same directory; the old name disappears.
Detailed explanation
mv draft.conf service.confCorrect. mv draft.conf service.conf renames the file.
Correct. mv draft.conf service.conf renames the file.
cp draft.conf service.confIncorrect. cp leaves the original and creates a copy.
Incorrect. cp leaves the original and creates a copy.
rm draft.conf service.confIncorrect. rm removes files and does not rename them.
Incorrect. rm removes files and does not rename them.
mkdir service.confIncorrect. mkdir creates a directory rather than renaming a file.
Incorrect. mkdir creates a directory rather than renaming a file.
Try it yourself
An example you can run in a temporary verification environment.
tmp=$(mktemp -d); touch "$tmp/draft.conf"; mv "$tmp/draft.conf" "$tmp/service.conf"; test -e "$tmp/service.conf" && test ! -e "$tmp/draft.conf" && echo renamed; rm -rf "$tmp"Expected result
renamedKey points
- mv moves and renames
- cp duplicates
- The old name is removed
Notes
- Environment: POSIX shell / 一時ディレクトリ
- 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.