If the destination directory exists when using the mv command, the behavior depends on how you specify the source and destination:
-
Moving a Directory into an Existing Directory:
- If you move a directory into an existing directory, the source directory will be placed inside the destination directory.
mv source_directory /path/to/existing_directory/In this case,
source_directorywill become a subdirectory ofexisting_directory. -
Renaming a Directory:
- If you specify a new name for the source directory that matches the name of an existing directory in the same location, the command will overwrite the existing directory unless you use the
-ioption to prompt for confirmation.
mv existing_directory new_directory_nameThis will rename
existing_directorytonew_directory_name, and ifnew_directory_namealready exists, it will be overwritten. - If you specify a new name for the source directory that matches the name of an existing directory in the same location, the command will overwrite the existing directory unless you use the
-
Using Options:
- To prevent accidental overwriting, you can use the
-ioption to prompt for confirmation before overwriting:
mv -i source_directory /path/to/existing_directory/ - To prevent accidental overwriting, you can use the
Summary
- If the destination is an existing directory, the source directory will be moved inside it.
- If the destination is a name that already exists in the same location, it may be overwritten unless you use the
-ioption.
