Get the App
SLTechnology News&Howtos  ›  Servers  › 

The method of using mv command to move files to a specified directory under linux

Shulou Source: shulou.com Published: 2022-06-02 00:34:35 09月20日 Update

This article is about how to use the mv command to move files to a specified directory under linux. The editor thought it was very practical, so I shared it with you as a reference. Let's follow the editor and have a look.

Under linux, you can use the mv command to move files to a specified directory: execute the [mv source destination] command. The source can be one or more files or directories, and the destination can be a single file or directory.

The mv command (short for move) is used to rename and move files and directories from one location to another.

The syntax of the mv command is:

Mv [OPTIONS] source destination

The source can be one or more files or directories, and the destination can be a single file or directory.

If you specify more than one file or directory as the source, the destination must be a directory. In this case, the source file is moved to the destination directory.

If a single file is specified as the source and the destination is an existing directory, the file is moved to the specified directory.

If you specify a single file as the source and a single file as the destination, you will rename the file.

If the source is a directory and the destination is not, rename the source to the destination, otherwise it will be moved to the destination directory.

To move a file or directory, you need to have write access to both the source and the destination. Otherwise, you will receive a permission denied error.

For example:

To move the file linuxidc.com.txt from the current working directory to the / tmp directory, you need to run:

Mv linuxidc.com.txt / tmp

To rename the file linuxidc.txt, specify the target file name (linuxidc.com.txt in this case):

Mv linuxidc.txt linuxidc.com.txt, thank you for your reading! The method of using mv command to move files to a specified directory under linux is shared here. I hope the above content can help you to some extent, so that you can learn more knowledge. If you think the article is good, you can share it and let more people see it.

Tags: File directory target move command single method multiple location content more permissions good practical situation file name article source file see knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Shulou Information macOS Apple vpn