How does Linux move a directory to another directory? In Linux, you can use the mv command to move a directory to another directory.

In Linux, you can use mvthe 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/documentsmove 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/documentsmove 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/sourcemove the directory /home/user/targetunder the directory, use the following command:

mkdir -p /home/user/target
mv /home/user/source /home/user/target

Among them, mkdir -pthe command is used to create a multi-level directory, that is, if /home/userthe directory does not exist, it will also be created. mvThe command is used to move the directory, and /home/user/sourcemove the source directory to the target directory /home/user/target.

Guess you like

Origin blog.csdn.net/weixin_42279822/article/details/130689837