010-150 · Question #2
Which of the following commands moves the directory ~/summer-vacation and its content to ~/vacation/2011?
The correct answer is D. mv ~/summer-vacation ~/vacation/2011. The mv command is used to move files and directories in Linux, and it does not require a recursive flag to move directories along with their contents.
Question
Which of the following commands moves the directory ~/summer-vacation and its content to ~/vacation/2011?
Options
- Amv ~/vacation/2011 ~/summer-vacation
- Bmove -R ~/summer-vacation ~/vacation/2011
- Cmv /home/summer-vacation /home/vacation/2011
- Dmv ~/summer-vacation ~/vacation/2011
- Emv -R ~/summer-vacation ~/vacation/2011
How the community answered
(55 responses)- A5% (3)
- B7% (4)
- C2% (1)
- D73% (40)
- E13% (7)
Why each option
The mv command is used to move files and directories in Linux, and it does not require a recursive flag to move directories along with their contents.
The source and destination arguments are reversed - this would move ~/vacation/2011 into ~/summer-vacation, not the other way around.
'move' is not a standard Linux command; the correct command is mv, and the -R flag is not a valid option for mv.
Using /home/summer-vacation is an incorrect absolute path - the home directory for a user is typically /home/username, not /home directly, so this path would be wrong for a normal user account.
The mv command natively moves entire directories and their contents without requiring any flags, making mv ~/summer-vacation ~/vacation/2011 the correct syntax. The source path ~/summer-vacation uses the tilde shortcut for the home directory, and the destination ~/vacation/2011 must already exist or will be created as the new name. No -R flag is needed because mv operates at the filesystem level by relinking inodes rather than copying data.
mv does not accept a -R flag; that flag is associated with cp for recursive copies. mv moves directories recursively by default without any flag.
Concept tested: Moving directories with the mv command
Source: https://www.gnu.org/software/coreutils/manual/coreutils.html#mv-invocation
Topics
Community Discussion
5D is your answer, no debate needed. The mv command handles directories and their contents without any flag like -R, so options B and E are dead wrong right there, move is not even a valid Unix command so B is doubly wrong. A has the source and destination swapped, and C uses /home/summer-vacation which is not the same path as ~/summer-vacation since the tilde expands to your actual home directory like /home/yourusername. D gets everything right, correct command, correct source, correct destination, done.
D is the one, and it makes sense once you remember that mv handles directories natively without any flag. The tilde shortcuts work perfectly here, so there is no need to spell out the full /home path like C tries to do.
The tricky part here is E, because people who come from cp or rsync muscle memory want to throw a -R in there, but mv does not need a recursive flag since it moves the directory as a whole unit. D is correct: mv ~/summer-vacation ~/vacation/2011 is all you need, assuming ~/vacation/2011 already exists or you want mv to rename summer-vacation to 2011 inside ~/vacation.
The reason E trips people up makes a lot more sense once you realize that mv on the same filesystem is just relinking a directory entry rather than touching any file data, so there is literally nothing to recurse through in the first place.
Saw D on my exam, tripped on E first since mv does not need -R.