In Linux, you can use mv
the command to move one directory into another.
The command format is as follows:
mv [选项] 源目录 目标目录
Among them, the options include:
-f
: Overwrite the target file (without prompting).-i
: Ask whether to overwrite the target file.-n
: Do not overwrite any existing target files.-v
: Display the detailed process of moving.
For example, to /home/user1/documents
move the directory into /home/user1/myfiles
:
mv /home/user1/documents /home/user1/myfiles
If the target directory does not exist, the source directory will be renamed to the target directory.
Alternatively, if you want to move a directory into a subdirectory under the current directory, you can use a relative path:
mv /home/user1/documents myfiles
This will /home/user1/documents
move to a subdirectory under the current directory myfiles
.
If the target directory does not exist, you can create the target directory first, and then move the source directory to the target directory.
For example, to /home/user/source
move the directory /home/user/target
under the directory, use the following command:
mkdir -p /home/user/target
mv /home/user/source /home/user/target
Among them, mkdir -p
the command is used to create a multi-level directory, that is, if /home/user
the directory does not exist, it will also be created. mv
The command is used to move the directory, and /home/user/source
move the source directory to the target directory /home/user/target
.