Home>Article>Operation and Maintenance> How to use the mv command to move files to a specified directory in Linux

How to use the mv command to move files to a specified directory in Linux

John Lennon
John Lennon Original
2020-10-29 11:22:56 26655browse

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

How to use the mv command to move files to a specified directory in Linux

Environment:

centos6 operating system

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

(Video tutorial recommendation:linux video tutorial)

The syntax of the mv command is as follows:

mv [OPTIONS] source destination

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

If multiple files or directories are specified as sources, the destination must be a directory. In this case, the source files will be moved to the target directory.

If a single file is specified as the source and the target destination is an existing directory, moves the file 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 target is not, rename the source to the target, otherwise it will be moved to the target directory.

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

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, Please specify the target file name (here is linuxidc.com.txt):

mv linuxidc.txt linuxidc.com.txt

Related recommendations:linux tutorial

The above is the detailed content of How to use the mv command to move files to a specified directory in Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn