Renaming or moving files in Unix — choose the correct command Which command is used on Unix/Linux to rename a file (and more generally to move a file to a new path or name)?
-
Arename
-
Bremove
-
Cmv
-
Dren
-
ENone of the above
Answer
Correct Answer: mv
Explanation
Introduction / Context:File management in Unix relies on a small set of powerful commands. Renaming is not a distinct operation; it is handled by the same command that moves files between paths. Recognizing the correct tool is essential for scripting and daily use.
Given Data / Assumptions:
- We are on a Unix/Linux system using standard coreutils or equivalent.
- The goal is to change a file’s name (possibly in the same directory).
- We want the canonical, always-available command.
Concept / Approach:
The mv command moves files and directories. If the destination is within the same directory but with a different name, the effect is a rename. While some distributions ship a rename utility, its syntax and availability vary and it handles pattern-based mass renames; mv is the portable tool. remove is not a standard command; file deletion uses rm. ren is a DOS/Windows alias, not standard on Unix.
Step-by-Step Solution:
Pick the universal tool:mv.Rename example: mv oldname.txt newname.txt.Move and rename example: mv oldname.txt docs/newname.txt.Verify with ls that the new name/path exists.Verification / Alternative check:
Consult man mv. You will see it supports moving and renaming. Experiment in a test directory to confirm behavior.
Why Other Options Are Wrong:
- rename: not guaranteed to exist or be consistent across systems.
- remove: not a standard command (use
rmto delete, not rename). - ren: DOS/Windows syntax; not standard on Unix.
- None of the above: incorrect because
mvis correct.
Common Pitfalls:
Overwriting existing files without -i; renaming across filesystems may copy then delete; remembering that permissions may restrict renames in directories without write/execute rights.
Final Answer:
mv