Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the mv command in Linux

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how to use the mv command in Linux. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

The Linux common command mv command is used to rename a file or directory or to move a file from one directory to another.

Mv is used to rename a file or directory

Supplementary note: source represents a source file or directory, and target represents a destination file or directory. If you move a file to an existing target file, the contents of the target file will be overwritten.

The mv command can be used to move source files to a target file, or to move a set of files to a target directory. Moving the source file to the destination file has two different results:

If the destination file is the path to a directory file, the source file is moved to that directory with the same file name.

If the destination file is not a directory file, the source file name (there can be only one) becomes the destination file name and overwrites an existing file with the same name. If the source and target files are in the same directory, the function of mv is to change the file name. When the target file is a directory file, there can be multiple source files or directory parameters, and all source files are moved to the target file. All files moved to this directory will retain the previous file name.

Note: the result of mv is different from that of cp. Mv is like a file "moving", and the number of files has not increased. While cp copies files, the number of files increases.

Syntax mv (option) (parameter) option-if backup=: needs to overwrite the file, overwrite the previous backup;-b: create a backup for the file before it is overwritten when the file exists;-f: if the target file or directory duplicates with the existing file or directory, the existing file or directory is overwritten directly -I: interactive operation, ask the user before overwriting, if the source file has the same name as the target file or the file in the target directory, ask the user whether to overwrite the target file. The user enters "y" to indicate that the target file will be overwritten, and "n" to cancel the movement of the source file. This avoids mistakenly overwriting the file. -- strip-trailing-slashes: delete the slash "/" in the source file;-S: specify a suffix for the backup file instead of using the default suffix;-- target-directory=: specify that the source file should be moved to the destination directory;-u: perform the move operation when the source file is newer than the destination file or the destination file does not exist. Parameter source file: a list of source files.

Target file: if the "target file" is the file name, rename the file to "target file" while moving the file; if "target file" is the directory name, move the source file to the "target file".

Instance moves all files in the directory / usr/men to the current directory (with. Represents):

Mv / usr/men/*. Move Fil

Mv file_1.txt / home/office/ moves multiple files

Mv file_2.txt file_3.txt file_4.txt / home/office/ mv * .txt / home/office/ mobile directory

Mv directory_1/ / home/office/ rename a file or directory

Mv file_1.txt file_2.txt # rename the file file_1.txt to file_2.txt rename the directory

Mv directory_1/ directory_2/ prints mobile information

Mv-v * .txt / home/office prompt whether to overwrite the file

Updates are performed only when the mv-I file_1.txt / home/office source file is newer than the target file

Mv-uv * .txt / home/office do not overwrite any existing files

Create a backup on mv-vn * .txt / home/office replication

Mv-bv * .txt / home/office unconditionally overwrites existing files

Mv-f * .txt / home/office Thank you for your reading! This is the end of this article on "how to use mv commands in Linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report