010-100 · Question #53
In order to rename the directory ~/bilder/letzter-urlaub to ~/bilder/sommer-2011, which command line could be used?
The correct answer is A. mv ~/bilder/letzter-urlaub ~/bilder/sommer-2011. In Linux, the mv command is used to both move and rename files and directories. Renaming is achieved by specifying a different destination path in the same parent directory.
Question
In order to rename the directory ~/bilder/letzter-urlaub to ~/bilder/sommer-2011, which command line could be used?
Options
- Amv ~/bilder/letzter-urlaub ~/bilder/sommer-2011
- Bmove ~/bilder/letzter-urlaub ~/bilder/sommer-2011
- Ccp -m ~/bilder/letzter-urlaub ~/bilder/sommer-2011
- Dcopy -m ~/bilde/letzter-urlaub ~/bilder/sommer-2011
- Erename ~/bilder/letzter-urlaub ~/bilder/sommer-2011
How the community answered
(33 responses)- A82% (27)
- C3% (1)
- D9% (3)
- E6% (2)
Why each option
In Linux, the mv command is used to both move and rename files and directories. Renaming is achieved by specifying a different destination path in the same parent directory.
The mv command is the standard Unix/Linux utility for moving and renaming files and directories. When the source and destination share the same parent directory but differ in name, mv effectively renames the directory without copying data.
move is not a valid Linux shell command; it is used in Windows CMD environments, not Unix-like systems.
cp is the copy command and has no -m flag for renaming; it would duplicate the directory rather than rename it.
copy is not a valid Linux command, and the source path contains a typo (~bilder instead of ~/bilder/), making this doubly incorrect.
rename (or prename) is used to rename files based on pattern substitution, not to move or rename directories by specifying explicit source and destination paths.
Concept tested: Linux mv command for renaming directories
Source: https://man7.org/linux/man-pages/man1/mv.1.html
Topics
Community Discussion
6A is your answer. On Linux, mv handles both moving and renaming, so pointing it at a new path within the same parent directory is all you need to rename that directory in one shot.
A is right, mv handles renames since both paths share the same parent. Does mv actually move data, or just update the directory entry?
Honestly I almost put E because I kept thinking rename was a real shell command for this, but when I actually sat down at the terminal during practice it was clear that rename works on files with patterns, not for just moving a directory to a new name. mv is the one that handles both moving and renaming for files and directories, so A is the right pick.
Good point on mv handling both jobs, though worth noting that rename does exist on many Linux systems (usually as a Perl script) and can technically rename a single file too, it just shines when you need to batch-rename with a regex pattern, which is why it felt wrong for the directory case.
A is right, mv handles both moving and renaming in Linux.
Yep, mv does both, and the key thing to remember for exam questions is that mv across different filesystems actually copies the data and deletes the source, while mv within the same filesystem just updates the directory entry, so if you see a question about inode behavior after a rename that detail can trip you up.